Search Unity

Pragma Strict work around for colliders?

Discussion in 'Scripting' started by tecra134, Feb 18, 2013.

  1. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    What is the work around for colliders when using Pragma Strict?

    Right now I have:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. function OnCollisionStay(other)
    5. {
    6.      if(other.gameObject == GameObject.Find("<ObjectName>"))
    7.      {
    8.      }
    9. }
    10.  
    I get an error saying, "gameObject is not a member of Object". When I delete the "#pragma strict" the error goes away. How should this be written out?

    Thanks!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not colliders specifically; always specify the type of variables. You haven't defined the type for "other".

    --Eric
     
  3. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    I'm not sure what you mean?

    Like:

    Code (csharp):
    1.  
    2. function OnCollisionStay(collisionInfo : other)
    3. {
    4. }
    5.  
    ?

    I thought the "other" would be assigned the info (collisionInfo: gameObject, collider, rigidbody, transform, relativeVelocity and contacts) as soon as the object with that script hits another object with a rigidbody/collider?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you have to define the type, as shown in the docs.

    It is, but that's something that happens at runtime, so it doesn't help at all when the script is compiled. You must always define the type for variables, either explicitly, or implicitly by supplying a value. But you can't supply a value for function parameters, so the only option is to declare the type explicitly.

    --Eric
     
  5. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    Awesome. That seemed to do it. Thanks!

    I just need to keep in mind to fully define my variables.