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

Problem with OnTriggerEnter

Discussion in 'Scripting' started by Thesaurus1233, Feb 3, 2015.

  1. Thesaurus1233

    Thesaurus1233

    Joined:
    Apr 5, 2014
    Posts:
    5
    Please if someone could help me with this, i tried everything and nothing worked.

    In the game I'm making in order to call a dead state I'm using a box collider to track if the player enters in a particular zone, but the problem is that it only tracks it if I'm pressing any of the a,s,d or w keys in the keyboard.

    This is the code.

    The OnTriggerEnter is call in line 48

    1. usingUnityEngine;
    2. usingSystem.Collections;
    3. publicclassPlayerManager:MonoBehaviour
    4. {
    5. publicboolDeath=false;
    6. publicboolAlive=false;
    7. publicboolMuerto;
    8. publicGameObjectGenerador;
    9. publicGameObjectStartButton;
    10. publicCharacterMotorMotor;
    11. publicstaticPlayerManagerInstanse;
    12. // Use this for initialization
    13. voidStart()
    14. {
    15. Instanse=this;
    16. }
    17. // Update is called once per frame
    18. voidUpdate()
    19. {
    20. if(gameObject.transform.position.y <=-3.5f)
    21. Death=true;
    22. if(!Alive)
    23. Generador.transform.position =newVector3(0,-0.57f,-4.12f);
    24. if(Death)
    25. {
    26. Generador.transform.position =newVector3(0,-0.57f,-4.12f);
    27. GenerateManager.Instante.BeforeObject=GenerateManager.Instante.Spawn;
    28. Motor.canControl =false;
    29. StartButton.SetActive(true);
    30. CameraMovement.Instanse.CanMoveCamera=false;
    31. gameObject.transform.position =newVector3(0.46f,1.102971f,-6);
    32. Camera.main.transform.position =newVector3(-0.07402526f,12.0031f,-1.937099f);
    33. foreach(GameObject gm inGenerateManager.Instante.BloquesGenerados)
    34. {
    35. Destroy(gm);
    36. }
    37. GenerateManager.Instante.BloquesGenerados.Clear();
    38. Death=false;
    39. }
    40. }
    41. voidOnTriggerEnter(Collider other)
    42. {
    43. if(other.gameObject.tag =="Generador")
    44. GenerateManager.Instante.DoGenerate=true;
    45. if(other.gameObject.tag =="Muerte")
    46. {
    47. Alive=false;
    48. Death=true;
    49. }
    50. }
    51. }
    If someone can help me fix this i will be very grateful.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Here are some things that you aparently didn't try
    Code (CSharp):
    1. voidOnTriggerEnter(Collider other){
    2.   Debug.Log(other.name)
    3. }
    This will make it clear if the collider is working or not

    On this page is a guide on what objects can interact with each other
    http://docs.unity3d.com/Manual/CollidersOverview.html
    make sure that your objects are the correct type (eg static trigger box collider zone, and rigidbody collider object entering it)