Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can't retrieve bool from other script (JS)

Discussion in 'Scripting' started by Warrior1424, May 3, 2014.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    This usually isn't a problem, but for some reason this doesn't want to work.
    I have two scripts (I've included only the important parts)

    PhysicsObject.js
    Code (csharp):
    1. public var PlayerCollide : boolean = true;
    PhysicsInteraction.js
    Code (csharp):
    1.  
    2. *heldobj gets stored*
    3. var properties = heldobj.GetComponent("PhysicsObject");
    4. if (properties.PlayerCollide);
    5. *stuff happens*
    Error:
    This is what I usually do to access other variables (At least I think)
     
  2. mafiadude1

    mafiadude1

    Joined:
    Jun 28, 2012
    Posts:
    59
    try:
    Code (csharp):
    1. var properties : PhysicsObject = heldobj.GetComponent("PhysicsObject") as PhysicsObject;
     
  3. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Nope, get this error:
     
  4. mafiadude1

    mafiadude1

    Joined:
    Jun 28, 2012
    Posts:
    59
    I don't use JS (in Unity atleast). But I remember that you had to do something special with JS scripts in certain folders.
    Either that or you don't have a script called PhysicsObject.
     
  5. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Yep, my bad.
    The actual script had a space between "Physics" and "Object"
    Thank you very much for your help kind sir!