I have been following a tutorial online about how to make an rts strategy game. In my scene, there are 3 object; A terrain called TerrainMain, the main camera, and a cube called target. Here is the code of my non-functioning c# script.
using UnityEngine;
using System.Collections;
public class MousePoint : MonoBehaviour {
RaycastHit hit;
private float raycastLength = 400;
void Update()
{
GameObject Target = GameObject.Find ("Target");
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast (ray, out hit, raycastLength)){
Debug.Log (hit.collider.name);
if (hit.collider.name == "TerrainMain")
{
Target.transform.position = hit.point;
}
}
Debug.DrawRay(ray.origin, ray.direction*raycastLength, Color.yellow);
}
}
I can get the cube to move around the terrain with my mouse, but I can’t actually pan in the x and z directions.