- Home /
How to engage an object if it's seen by my camera??
Here's the code, however i'd like to engage an object that is seen by my camera
for (var width = 1; Screen.width; width++){
for (var height = 1; Screen.height; height++){
var ray = Camera.main.ScreenPointToRay (Vector3(width, height, 0));
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, Mathf.Infinity ) && hit.transform.tag == tagLock){
Debug.Log("finalmente!!");
}
}
}
Comment
'engage'? what do you mean exactly? You want to attack it? Want to marry it? :p want to get a reference to it?
excuse me for my english, however i'd like to check if the ray hit the target so that i can shoot my rocket to follow it
Answer by SisterKy · Sep 02, 2011 at 07:39 PM
Hmmm... it took me a while to figure out what you are trying to achieve with your code... in theory that's probably possible... but seems quite cumbersome. I think here you'll find some more elegant approaches for your problem...? http://answers.unity3d.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html
Or am I missing the point of your question?
Greetz, Ky.