Search Unity

active bool from another script

Discussion in 'Scripting' started by Helladah, Feb 15, 2019.

  1. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    Hi, i need to change values of scripts from another scripts, this is what i have written.

    Code (CSharp):
    1. public Score putos;
    2.  
    3. putos = GetComponent<Score>();
    4.  
    5. putos.active = true;
    6.  
    But the console sends me this message:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Stone.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Mainly/Player/Stone.cs:45)
    any idea of what can i do?
     
  2. simonlvschal

    simonlvschal

    Joined:
    Nov 17, 2015
    Posts:
    266
    GetComponent is on the Object that the script exist on.. aka if u want to use GetComponent like that Score needs to be on the object your calling the it on.
     
  3. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    the script its attached to a game object, and this one its onto the script inspector of the first