So I have broken my sene down into a very simple, scene with one “Cube” to test my targeting solution,
I get Debug.log “MouseDown”
however I do not get Debug.log “RayCasted” (after ray-cast has been fired, and before it hits anything.)
So apparently my Raycasts are not Firing at all.
this is for the main controll-system and function all of the Capital ships for my game.
Everything is layered correctly.
(Using Layer Masks to only Select selectableObjects that are then Assigned to “Target.Gameobject”)
then I can do stuff. (follow target, train my guns to this large, launch fighters at this target act.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TargetIngSystem : MonoBehaviour {
Ray ray;
RaycastHit hit;
public int number = 0;
public GameObject Target;
public LayerMask LayerMaskSC;
public Targeted Locked;
public bool IsTargeted;
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
void Update () {
if (Input.GetMouseButtonDown (0)) {
Debug.Log ("MouseDown");
// Reset ray with new mouse position
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, LayerMaskSC)){
Debug.Log ("RayCasted"); // NOT FIREING
if (hit.collider.gameObject) {
Debug.Log ("Hit");
Target = hit.collider.gameObject;
}
}
}
}
//-------------------------------------------------------------------------------------
}