Search Unity

Simple collision code fails to work.

Discussion in 'Editor & General Support' started by AAcat, Nov 29, 2015.

  1. AAcat

    AAcat

    Joined:
    Apr 11, 2015
    Posts:
    19
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var SpawnPoint: Transform;
    4.  
    5. var player : GameObject;
    6.  
    7. var maxFallDis = -20;
    8.  
    9. function Update()
    10. {
    11.     if(transform.position.y <= maxFallDis)
    12.     {
    13.        player.transform.position = SpawnPoint.position;
    14.     }
    15. }
    16. //below is where the problem occurs
    17. function OnCollisionStay (collisionInfo: Collision){
    18.     if (Collision.collider.tag == "bad") {
    19.         player.transform.position = SpawnPoint.position;
    20.     }
    21. }
    22.  
    23.  
    I used code based off of threads from 3 years ago, so this is probably out dated. Can someone tell me the working version of this? (basically when the object touches another object, the main object goes to the spawn-points position, however its not working.)
    The error message I get is: BCE0020: An instance of type 'UnityEngine.Collision' is required to access non static member 'collider'.
     
    Last edited: Nov 29, 2015