Hello, i am using a script to select units with raycasting. While the script used to work just fine. All of a sudden it stopped hitting both the terrain and the objects. I have many objects with colliders on them.
I haven't changed the lenght of the ray, nor the camera position.
I am checking in the code whether the name of the object that's hit is Archer or not. But even if i remove that condition. The Position of the object hit is always 0,0,0. There's nothing in front of the camera.
Please help me.
Here is the code that uses raycasting.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UnitSelectArcher : MonoBehaviour {
Ray ourRay;
RaycastHit hit;
public Camera MainCamera;
public bool unitSelected=false;
public Button MoveButton;
public Button AttackButton;
public Canvas ActionMenu;
public string unitName="Archer";
float targetX;
float targetZ;
bool Moving=false;
public float speed=2f;
public GameObject kup;
public Transform spawnPoint;
// Use this for initialization
void Start () {
MainCamera = MainCamera.GetComponent ();
MoveButton = MoveButton.GetComponent
↧