So I have this bridge that is standing up vertically and if you point and click at it, it will fall down frontwards. If you click at it again while it is down it will go stand up vertically again.
What I want to do is duplicate the bridge in multiple places. However, when I duplicate one and try clicking on it, the bridge will go down but when I try clicking on it to go up again the bridge teleports or disappears into the original bridge I tried duplicating it from.
It’s pretty frustrating…
I have 2 codes for my Bridge
this one is attached to my bridge
var anim:boolean=false;
function Start()
{
}
function Update(){
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (collider.Raycast (ray, hit, 1000)) {
Debug.DrawLine (ray.origin, hit.point);
if(Input.GetMouseButtonDown(0))
{
Wait();
}
}
}
function Wait()
{
anim=!anim;
if(anim)
{
animation.CrossFade("BridgeOpen");
Debug.Log("Bridgeopen");
}
if(!anim)
{
animation.CrossFade("BridgeClose");
Debug.Log("Bridgeclose");
}
}
this one is not attached to my bridge
function Update ()
{
// left clicky thing
if(Input.GetMouseButtonDown(0))
{
//used to start our raycast into the 3d world
var ray:Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
//stores the object the ray hits in the Scene
var hit:RaycastHit;
//check if the ray collides with a Collider in the Scene
if(Physics.Raycast(ray.origin,ray.direction,hit,Mathf.Infinity))
{
//if the ray collides with a Collider in the Scene
Debug.Log(hit.transform.name); //print name of thing hit
var bridge = hit.transform.GetComponent(Bridge); // Door is script name
// if the Door script is attached to the object
if(bridge)
{
// use public things (variables or functions)
bridge.PlayBridgeAnimation();
}
}
}
}