Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Changing public variable from a function (JS)

Discussion in 'Scripting' started by rmele09, Oct 31, 2015.

  1. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    712
    How can I change a public/inspector variable from a function? I left out where I call the function for simplicity sake. This code here is throwing an error:

    Code (JavaScript):
    1. // The Variable I am trying to change
    2. var target : Transform;
    3.  
    4. function NavP1 ()
    5. {
    6.     target = GameObject.FindWithTag  ("NavP1").transform;
    7. }
    I have tried creating the variable inside the function and that seems to not work either. Thanks!
     
  2. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    712
    Ugh I got it to work. The problem was actually in the code I didn't upload, go figure.