I got 2 scripts. The first one is called "DoorOpen" and is attached to a door. The second one is called "OpenObjects" which is connected to my player. What i want to happen: The script "OpenObjects" should when (drawGUI == true && Input.GetButtonDown("Fire1")) tell the script "DoorOpen" script that doorIsClosed = true And the "DoorOpen" script should then do the animations. But what happens is that my console says "Assets/OpenObjects.js(14,16): BCE0005: Unknown identifier: 'door'." Script information: DoorOpen: Code (JavaScript): #pragma strict static var doorIsClosed = false; var theDoor : Transform; function changeDoorState () { if (doorIsClosed == true) { theDoor.animation.CrossFade("DoorOpen"); //theChest.audio.PlayOneShot(); doorIsClosed = false; yield WaitForSeconds(3); theDoor.animation.CrossFade("DoorClose"); //theChest.audio.PlayOneShot(); doorIsClosed = true; } } OpenObjects: Code (JavaScript): #pragma strict var hit : RaycastHit; var Reach : float = 2.0; var RayHit : boolean; private var drawGUI = false; private var doorOpen : DoorOpen; function Awake () { door = GameObject.FindGameObjectWithTag("door"); doorOpen = door.GetComponent(DoorOpen); } function Update () { var fwd = transform.TransformDirection (Vector3.forward); Debug.DrawRay(transform.position, fwd * Reach, Color.red); if (Physics.Raycast (transform.position, fwd, hit, Reach) && hit.transform.tag == "door") { RayHit = true; drawGUI = true; } else { RayHit = false; drawGUI = false; } { if (drawGUI == true && Input.GetButtonDown("Fire1")) { doorOpen.doorIsClosed = true; } } } function OnGUI () { if (drawGUI == true) { GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Click to open"); } }
I dont know javascript but you dont have a declaration for 'door' is that a problem in javascript. you should also check that you are in fact getting an object returned on lines 13 and 14.
change line 13 from; door = GameObject.FindGameObjectWithTag("door"); to var door = GameObject.FindGameObjectWithTag("door"); Hope this helps!
Is the console giving the same error message? Unknown Identifier Error is an error caused by not declaring a Variable before it is used like a = b or MyObject = GameObject.FindGameObjectWithTag("Tag") I read that javascript requires Implicit Variable Declaration which means that it needs you to tell it what all Variables are before you use them. var a = b or var MyObject = GameObject.FindGameObjectWithTag("Tag") Another thing to note is, i dont know how everything is setup on your side but if you have more than one door and they both have a Tag 'door', expect to reference the wrong door with your current code. also this is just a suggestion, try and rethink your logic... let me explain. this is not a put down..... an object should be solely responsible for knowing its state at all times. if a door is closed ONLY the door should know its closed. That sounds strange how does a door know its closed.... By doing it that way you can implement and code things in a much simpler way. LOGIC FOLLOWING.... ray hits door ray script asks door to activate (or maybe more precisely open or close) door checks its current state then either opens or closes and does whatever you need it to do door replies "OK" or "I am already open" or whatever you need. So in your case OpenObjects Script only needs to be concerned with what the ray is hitting and uses the same code to request activation from anything.....GetObject -> RequestActivation then put a routine on every object that handles this request Cup.Request might = drink door.Request might = OpenClose etc etc Anyway please check your console and be sure the message is still the same or if its changed
so i have the script to only be used on the door, but now when the animation plays it lets the door go through the player, and the player cant normally go through... Its only when the animation plays?