Hi guys, can somebody tell me, what is wrong with my code? It seems, the problem is when declaring variables ray and rayCastHit bacause the compiler does not know them afterwards.
using UnityEngine;
using System.Collections;
public class TouchPlayerScript : MonoBehaviour {
private Ray ray;
private RaycastHit rayCastHit;
void Update (){
if (Input.GetMouseButton (0)) {
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, rayCastHit)) {
transform.position.x = rayCastHit.point.x;
transform.position.y = rayCastHit.point.y;
}
}
}
}
Thanks for any help.