Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to disable a script from another script.

Discussion in 'Scripting' started by Rettamkrad, Aug 3, 2020.

  1. Rettamkrad

    Rettamkrad

    Joined:
    Jun 9, 2020
    Posts:
    2
    So I'm a complete noob when it comes to unity and c# ( I only started playing with it about 2 months ago) I'm currently creating an endless runner that when you collide with an obstacle the player can rewind time by hold spacebar.

    All these things work fine but while the rewinding time works the spawn point continues to spawn new enemies.

    After watching a few tutorials and trying to do it myself I'm here to see if anyone can help.

    I'm tried creating

    Public GameObject Spawn;
    Attached the spawn point object with the script attached.
    And trying to call it on

    If (Input.GetKeyDown(Keycode.space))
    Spawn.GetComponant<spawnPoint>().enabled = false;

    And

    And the reverse when space is released.

    But I can't seem to get it to work, I would very appropriate of anyone who could offer some help.

    Thanks.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,474
    Without more context of how your code is setup, it's hard to say why it doesn't work. You'll probably want to show your code for both your spawning and your disable/enable code a bit more so we can help you out.

    Also note, in case it's not a typo.

    KeyCode.Space

    requires the Space to be capital.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    3,403
    Can you elaborate on what you mean by it not working? Are you getting compile errors, or is it just not working the way you want when you play the game? What's happening instead of what you want to happen?
     
unityunity