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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Player Collision Script Problem

Discussion in 'Scripting' started by unity_07FcQsbZo3uMBw, Dec 28, 2019.

  1. unity_07FcQsbZo3uMBw

    unity_07FcQsbZo3uMBw

    Joined:
    Dec 28, 2019
    Posts:
    1
    Hi, I have a question, I applied the player collision part
    void OnCollisionEnter(Collision collisionInfo)
    {
    if (collisionInfo.collider.tag == "Obstacle");
    {
    movement.enabled = false;
    }
    }
    but when i run the game, the PlayerMovement box unchecks itself and the main cube doesnt move. I need to check it by myself and than mouse click on the cube once, so that i can use a and d to steer it, why does that happen ? Appreciate the help, thanks
     
  2. BenVenNL

    BenVenNL

    Joined:
    Oct 14, 2019
    Posts:
    56
    Hard to say why it unchecks it self. Maybe something else is checking/unchecking it?

    Did you try setting the PlayerMovement to 'true' on Awake?

    The second part is normal. Anytime you click on something outside the play window inside Unity, you need to click somewhere inside this window to 'connect to the game' again. You don't even need to click the cube, clicking anywhere inside the window will do the trick.
     
  3. NanushTol

    NanushTol

    Joined:
    Jan 9, 2018
    Posts:
    121
    it might be that the variable "movement" is referencing the PlayerMovement and you are setting it off in the code by calling movement.enabled = false;

    if you could post the rest of the code and also put it in a code snippet it will be easier to help you