I found out about raycasts recently, and I want to try and use one to make the player’s phone light freeze enemies in place when it touches them by casting a ray from the phone that sends a message to enemies when it touches them to stop all movement and animation until the ray isn’t touching them anymore. The problem is I have almost no experience with Javascript or C#, so I have no idea what I’m doing S: I’ve looked at plenty of tutorials, but none have exactly what I need. Would anyone be able to help, maybe come up with a raycasting script I could go off of?
This is all I have for my raycast script.
#pragma strict
private var lineTransform : Vector3;
private var startTransform : Vector3;
function Start ()
{
lineTransform = transform.position;
startTransform = transform.position;
}
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5,0));
if (Physics.Raycast (ray, hit, 100)) {
Debug.DrawLine (ray.origin, hit.point);
}
//Debug.DrawRay(startTransform, lineTransform, Color.red);
}
There’s not really anything there, except a blank ray.