Note: This script is attached to the object behind and object in front.
I need to make it so when there is an object in front of another object, the object that is behind changes its boolean from false to true. Here is what I tried to do with a raycast:
function Update(){
var fwd = transform.TransformDirection (-Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 1)) {
placedObject = true;
}
}
Whats happening at the moment is that the placedObject variable is being set true for the object in front. I need it to be set true for the object behind. I have been trying to fix this for ages please help!
Just to re-iterate, if object is in front, do this to the object it is in front of.
This would be a good job for Dot Product : http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Dot.html There is a demonstration video here : www.youtube.com/watch?v=JAAGdF-Wdas
– AlucardJay