Hi all i am having trouble with a script. This is the issue: I have a raycast script that sends a raycast from the camera into the scene and checks what object (with a collider) has being touched. After this the script turns around another gameojbect (defined by a transform in the script).
The problem is that i want the raycast script only to do something when one specific object has been touched. But now it responds to all the object in the scene with a collider. And i can’t remove the collider because it’s used for other functions in the game.
I tried to do this by putting a second transfrom into the script so i can select in the menu which gameobject should be checked for touch but i can’t get the syntax right.
This is my script:
private var hit : RaycastHit;
private var ray : Ray;//wanneer raken we het object??
var speed : float = 100;
var turntarget: Transform;
var touchtarget: Transform;
function FixedUpdate () {
if(Input.touchCount == 1) {
ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
// bereken beweging sinds het laatste frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
turntarget.transform.Rotate(Vector3.up * touchDeltaPosition.x * Time.deltaTime * speed);
}
}
}
}