Variables in other scripts in unity The Next CEO of Stack OverflowHow do I prompt for Yes/No/Cancel input in a Linux shell script?What is the scope of variables in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?How to declare and use boolean variables in shell script?How to check if a variable is set in Bash?JavaScript check if variable exists (is defined/initialized)Is there a reason for C#'s reuse of the variable in a foreach?Script instance is returning nullcontrol object rotation by mouse click in unity

Is micro rebar a better way to reinforce concrete than rebar?

Legal workarounds for testamentary trust perceived as unfair

Math-accent symbol over parentheses enclosing accented symbol (amsmath)

Does soap repel water?

I want to delete every two lines after 3rd lines in file contain very large number of lines :

Bartok - Syncopation (1): Meaning of notes in between Grand Staff

How do I align (1) and (2)?

Is French Guiana a (hard) EU border?

How is this set of matrices closed under multiplication?

Easy to read palindrome checker

What's the best way to handle refactoring a big file?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

Can you be charged for obstruction for refusing to answer questions?

Proper way to express "He disappeared them"

What did we know about the Kessel run before the prequels?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Poetry, calligrams and TikZ/PStricks challenge

Find non-case sensitive string in a mixed list of elements?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

What does "Its cash flow is deeply negative" mean?

Does increasing your ability score affect your main stat?

INSERT to a table from a database to other (same SQL Server) using Dynamic SQL

Prepend last line of stdin to entire stdin

0 rank tensor vs 1D vector



Variables in other scripts in unity



The Next CEO of Stack OverflowHow do I prompt for Yes/No/Cancel input in a Linux shell script?What is the scope of variables in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?How to declare and use boolean variables in shell script?How to check if a variable is set in Bash?JavaScript check if variable exists (is defined/initialized)Is there a reason for C#'s reuse of the variable in a foreach?Script instance is returning nullcontrol object rotation by mouse click in unity










1















I am trying to create a game in Unity 2d. I have finished most of what I want to do and have moved on to the enemies. The enemies (dragons) come in from different points of screen. To do this I have placed sprite game objects where I want the dragon to spawn. I have made all of these objects a child of another object called DragonAncores. I attached a script to DragonAncores which says this...



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragonTracker : MonoBehaviour
// is gold dragon in play?
public bool GoldDragonInit = false;
// curently active dragons
public int DragonCount = 0;
// defalts to 5
public int Difficulty = 5;



I am then attaching a script to each sprite which will eventually summon in a dragon Prefab (containing 2 colliders and an animator) biased of If statment logic derived from the other variables.



below is the code i am using.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Dragons : MonoBehaviour
// same as GoldDragonInit
bool GoldDragonSpawn = false;
// same number as DragonCount in DragonTrackeer
int LiveDragons;
// same as Difficulty
int DifLev;
//get cariables from other script
DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;

System.Random RNG= new System.Random();
void update()

RSpawn=RNG.Next(0,2)
DragonType=RNG.Next(0,101)
if (RSpawn = 1) ;

if (LiveDragons > DifLev) ;

if (DragonType > 99) ;

// summon regular dragon

if (DragonType = 100) ;

if (GoldDragonSpawn = true) ;

// summon gold dragon








This is throwing up this error list.
Error List



This shows my hierarchy in unity and the anchor points (the Squair crosshair looking things)
Unity Hierarchy and anchor points



I have looked for other threads that adress this topic and they all try different methods, non work.
i am using Unity 2018.2.18f1



thanks in advanced










share|improve this question


























    1















    I am trying to create a game in Unity 2d. I have finished most of what I want to do and have moved on to the enemies. The enemies (dragons) come in from different points of screen. To do this I have placed sprite game objects where I want the dragon to spawn. I have made all of these objects a child of another object called DragonAncores. I attached a script to DragonAncores which says this...



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DragonTracker : MonoBehaviour
    // is gold dragon in play?
    public bool GoldDragonInit = false;
    // curently active dragons
    public int DragonCount = 0;
    // defalts to 5
    public int Difficulty = 5;



    I am then attaching a script to each sprite which will eventually summon in a dragon Prefab (containing 2 colliders and an animator) biased of If statment logic derived from the other variables.



    below is the code i am using.



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Dragons : MonoBehaviour
    // same as GoldDragonInit
    bool GoldDragonSpawn = false;
    // same number as DragonCount in DragonTrackeer
    int LiveDragons;
    // same as Difficulty
    int DifLev;
    //get cariables from other script
    DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;

    System.Random RNG= new System.Random();
    void update()

    RSpawn=RNG.Next(0,2)
    DragonType=RNG.Next(0,101)
    if (RSpawn = 1) ;

    if (LiveDragons > DifLev) ;

    if (DragonType > 99) ;

    // summon regular dragon

    if (DragonType = 100) ;

    if (GoldDragonSpawn = true) ;

    // summon gold dragon








    This is throwing up this error list.
    Error List



    This shows my hierarchy in unity and the anchor points (the Squair crosshair looking things)
    Unity Hierarchy and anchor points



    I have looked for other threads that adress this topic and they all try different methods, non work.
    i am using Unity 2018.2.18f1



    thanks in advanced










    share|improve this question
























      1












      1








      1








      I am trying to create a game in Unity 2d. I have finished most of what I want to do and have moved on to the enemies. The enemies (dragons) come in from different points of screen. To do this I have placed sprite game objects where I want the dragon to spawn. I have made all of these objects a child of another object called DragonAncores. I attached a script to DragonAncores which says this...



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class DragonTracker : MonoBehaviour
      // is gold dragon in play?
      public bool GoldDragonInit = false;
      // curently active dragons
      public int DragonCount = 0;
      // defalts to 5
      public int Difficulty = 5;



      I am then attaching a script to each sprite which will eventually summon in a dragon Prefab (containing 2 colliders and an animator) biased of If statment logic derived from the other variables.



      below is the code i am using.



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class Dragons : MonoBehaviour
      // same as GoldDragonInit
      bool GoldDragonSpawn = false;
      // same number as DragonCount in DragonTrackeer
      int LiveDragons;
      // same as Difficulty
      int DifLev;
      //get cariables from other script
      DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;

      System.Random RNG= new System.Random();
      void update()

      RSpawn=RNG.Next(0,2)
      DragonType=RNG.Next(0,101)
      if (RSpawn = 1) ;

      if (LiveDragons > DifLev) ;

      if (DragonType > 99) ;

      // summon regular dragon

      if (DragonType = 100) ;

      if (GoldDragonSpawn = true) ;

      // summon gold dragon








      This is throwing up this error list.
      Error List



      This shows my hierarchy in unity and the anchor points (the Squair crosshair looking things)
      Unity Hierarchy and anchor points



      I have looked for other threads that adress this topic and they all try different methods, non work.
      i am using Unity 2018.2.18f1



      thanks in advanced










      share|improve this question














      I am trying to create a game in Unity 2d. I have finished most of what I want to do and have moved on to the enemies. The enemies (dragons) come in from different points of screen. To do this I have placed sprite game objects where I want the dragon to spawn. I have made all of these objects a child of another object called DragonAncores. I attached a script to DragonAncores which says this...



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class DragonTracker : MonoBehaviour
      // is gold dragon in play?
      public bool GoldDragonInit = false;
      // curently active dragons
      public int DragonCount = 0;
      // defalts to 5
      public int Difficulty = 5;



      I am then attaching a script to each sprite which will eventually summon in a dragon Prefab (containing 2 colliders and an animator) biased of If statment logic derived from the other variables.



      below is the code i am using.



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class Dragons : MonoBehaviour
      // same as GoldDragonInit
      bool GoldDragonSpawn = false;
      // same number as DragonCount in DragonTrackeer
      int LiveDragons;
      // same as Difficulty
      int DifLev;
      //get cariables from other script
      DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;

      System.Random RNG= new System.Random();
      void update()

      RSpawn=RNG.Next(0,2)
      DragonType=RNG.Next(0,101)
      if (RSpawn = 1) ;

      if (LiveDragons > DifLev) ;

      if (DragonType > 99) ;

      // summon regular dragon

      if (DragonType = 100) ;

      if (GoldDragonSpawn = true) ;

      // summon gold dragon








      This is throwing up this error list.
      Error List



      This shows my hierarchy in unity and the anchor points (the Squair crosshair looking things)
      Unity Hierarchy and anchor points



      I have looked for other threads that adress this topic and they all try different methods, non work.
      i am using Unity 2018.2.18f1



      thanks in advanced







      c# variables unity3d scripting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 15:26









      AlexAlex

      2819




      2819






















          4 Answers
          4






          active

          oldest

          votes


















          1














          There are a few errors in your code here. The following is incorrect.



          //get cariables from other script
          DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


          The correct way to access this, seeing as you said DragonAncors is the parent would be:



          GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;


          This sets the GoldDragonInit Boolean to the value of GoldDragonSpawn. This has to be inside a function, as you have it outside of a function I presume you needed this set on start. Therefore I have placed it in the void Start() function. This is called at the start of the game(loaded scene).



          You also do not need semi-colons ; after an if statement, however it does need to appear after every line of difinitive code. The code you have provided should instead look like this.



          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class Dragons : MonoBehaviour
          // same as GoldDragonInit
          bool GoldDragonSpawn = false;
          // same number as DragonCount in DragonTrackeer
          int LiveDragons;
          // same as Difficulty
          int DifLev;
          void Start()

          // variables from other script
          GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;

          System.Random RNG= new System.Random();
          void update()

          RSpawn=RNG.Next(0,2);
          DragonType=RNG.Next(0,101);
          if (RSpawn = 1)

          if (LiveDragons > DifLev)

          if (DragonType > 99)

          // summon regular dragon

          if (DragonType = 100)

          if (GoldDragonSpawn = true)

          // summon gold dragon








          This works because DragonTracker is a script in the objects parent. If this was not the case then GetComponentInParent().GoldDragonInit = GoldDragonSpawn; would be replaced like so:



          [SerializeField]
          private GameObject DragonAncors;
          void Start()

          DragonAncors.GetComponent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;






          share|improve this answer






























            1














            This is not valid c# code:



            //get cariables from other script
            DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


            Why? Because it isn't inside a method.



            Also, the comment is wrong. It isn't getting a variable (typo, too), its setting a variable in another script!



            The reason for the first...16 problems Visual Studio is complaining about are because of this line.



            At this location you are only allowed to declare methods, fields, and properties and you're currently trying to access another class and change one of its members (something you can only do inside a method).



            Additionally, you have .cs which I assume is because "DragonAnchors.cs is the file name!" which you don't need to do. I'm not sure how to go about rewriting this line (inside Start()) as I'm not sure what you're trying to actually do. That is, I don't know where an instance of DragonAnchors actually resides. You're calling GetComponent(), which is typically reserved for accessing components attached to game objects, but as you've attempted to do so on a static class reference, I'm not sure if you meant to call it on this or on something else.






            share|improve this answer






























              1














              This is how you can get to DragonTracker:



              DragonTracker dt = GameObject.Find("DragonAncores").GetComponent<DragonTracker>()
              Debug.Log(dt.DragonCount);





              share|improve this answer






























                0














                There are a lot of errors there and they may take some steps to go through, but first things first you should clear up the issue with the code you're trying to use being unsupported. Go into the project settings and change the compiler language version as it notes on the 5th error down. This should allow you to use the newer functionality.






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function ()
                  StackExchange.using("externalEditor", function ()
                  StackExchange.using("snippets", function ()
                  StackExchange.snippets.init();
                  );
                  );
                  , "code-snippets");

                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "1"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066284%2fvariables-in-other-scripts-in-unity%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  1














                  There are a few errors in your code here. The following is incorrect.



                  //get cariables from other script
                  DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                  The correct way to access this, seeing as you said DragonAncors is the parent would be:



                  GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;


                  This sets the GoldDragonInit Boolean to the value of GoldDragonSpawn. This has to be inside a function, as you have it outside of a function I presume you needed this set on start. Therefore I have placed it in the void Start() function. This is called at the start of the game(loaded scene).



                  You also do not need semi-colons ; after an if statement, however it does need to appear after every line of difinitive code. The code you have provided should instead look like this.



                  using System.Collections;
                  using System.Collections.Generic;
                  using UnityEngine;

                  public class Dragons : MonoBehaviour
                  // same as GoldDragonInit
                  bool GoldDragonSpawn = false;
                  // same number as DragonCount in DragonTrackeer
                  int LiveDragons;
                  // same as Difficulty
                  int DifLev;
                  void Start()

                  // variables from other script
                  GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;

                  System.Random RNG= new System.Random();
                  void update()

                  RSpawn=RNG.Next(0,2);
                  DragonType=RNG.Next(0,101);
                  if (RSpawn = 1)

                  if (LiveDragons > DifLev)

                  if (DragonType > 99)

                  // summon regular dragon

                  if (DragonType = 100)

                  if (GoldDragonSpawn = true)

                  // summon gold dragon








                  This works because DragonTracker is a script in the objects parent. If this was not the case then GetComponentInParent().GoldDragonInit = GoldDragonSpawn; would be replaced like so:



                  [SerializeField]
                  private GameObject DragonAncors;
                  void Start()

                  DragonAncors.GetComponent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;






                  share|improve this answer



























                    1














                    There are a few errors in your code here. The following is incorrect.



                    //get cariables from other script
                    DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                    The correct way to access this, seeing as you said DragonAncors is the parent would be:



                    GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;


                    This sets the GoldDragonInit Boolean to the value of GoldDragonSpawn. This has to be inside a function, as you have it outside of a function I presume you needed this set on start. Therefore I have placed it in the void Start() function. This is called at the start of the game(loaded scene).



                    You also do not need semi-colons ; after an if statement, however it does need to appear after every line of difinitive code. The code you have provided should instead look like this.



                    using System.Collections;
                    using System.Collections.Generic;
                    using UnityEngine;

                    public class Dragons : MonoBehaviour
                    // same as GoldDragonInit
                    bool GoldDragonSpawn = false;
                    // same number as DragonCount in DragonTrackeer
                    int LiveDragons;
                    // same as Difficulty
                    int DifLev;
                    void Start()

                    // variables from other script
                    GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;

                    System.Random RNG= new System.Random();
                    void update()

                    RSpawn=RNG.Next(0,2);
                    DragonType=RNG.Next(0,101);
                    if (RSpawn = 1)

                    if (LiveDragons > DifLev)

                    if (DragonType > 99)

                    // summon regular dragon

                    if (DragonType = 100)

                    if (GoldDragonSpawn = true)

                    // summon gold dragon








                    This works because DragonTracker is a script in the objects parent. If this was not the case then GetComponentInParent().GoldDragonInit = GoldDragonSpawn; would be replaced like so:



                    [SerializeField]
                    private GameObject DragonAncors;
                    void Start()

                    DragonAncors.GetComponent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;






                    share|improve this answer

























                      1












                      1








                      1







                      There are a few errors in your code here. The following is incorrect.



                      //get cariables from other script
                      DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                      The correct way to access this, seeing as you said DragonAncors is the parent would be:



                      GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;


                      This sets the GoldDragonInit Boolean to the value of GoldDragonSpawn. This has to be inside a function, as you have it outside of a function I presume you needed this set on start. Therefore I have placed it in the void Start() function. This is called at the start of the game(loaded scene).



                      You also do not need semi-colons ; after an if statement, however it does need to appear after every line of difinitive code. The code you have provided should instead look like this.



                      using System.Collections;
                      using System.Collections.Generic;
                      using UnityEngine;

                      public class Dragons : MonoBehaviour
                      // same as GoldDragonInit
                      bool GoldDragonSpawn = false;
                      // same number as DragonCount in DragonTrackeer
                      int LiveDragons;
                      // same as Difficulty
                      int DifLev;
                      void Start()

                      // variables from other script
                      GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;

                      System.Random RNG= new System.Random();
                      void update()

                      RSpawn=RNG.Next(0,2);
                      DragonType=RNG.Next(0,101);
                      if (RSpawn = 1)

                      if (LiveDragons > DifLev)

                      if (DragonType > 99)

                      // summon regular dragon

                      if (DragonType = 100)

                      if (GoldDragonSpawn = true)

                      // summon gold dragon








                      This works because DragonTracker is a script in the objects parent. If this was not the case then GetComponentInParent().GoldDragonInit = GoldDragonSpawn; would be replaced like so:



                      [SerializeField]
                      private GameObject DragonAncors;
                      void Start()

                      DragonAncors.GetComponent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;






                      share|improve this answer













                      There are a few errors in your code here. The following is incorrect.



                      //get cariables from other script
                      DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                      The correct way to access this, seeing as you said DragonAncors is the parent would be:



                      GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;


                      This sets the GoldDragonInit Boolean to the value of GoldDragonSpawn. This has to be inside a function, as you have it outside of a function I presume you needed this set on start. Therefore I have placed it in the void Start() function. This is called at the start of the game(loaded scene).



                      You also do not need semi-colons ; after an if statement, however it does need to appear after every line of difinitive code. The code you have provided should instead look like this.



                      using System.Collections;
                      using System.Collections.Generic;
                      using UnityEngine;

                      public class Dragons : MonoBehaviour
                      // same as GoldDragonInit
                      bool GoldDragonSpawn = false;
                      // same number as DragonCount in DragonTrackeer
                      int LiveDragons;
                      // same as Difficulty
                      int DifLev;
                      void Start()

                      // variables from other script
                      GetComponentInParent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;

                      System.Random RNG= new System.Random();
                      void update()

                      RSpawn=RNG.Next(0,2);
                      DragonType=RNG.Next(0,101);
                      if (RSpawn = 1)

                      if (LiveDragons > DifLev)

                      if (DragonType > 99)

                      // summon regular dragon

                      if (DragonType = 100)

                      if (GoldDragonSpawn = true)

                      // summon gold dragon








                      This works because DragonTracker is a script in the objects parent. If this was not the case then GetComponentInParent().GoldDragonInit = GoldDragonSpawn; would be replaced like so:



                      [SerializeField]
                      private GameObject DragonAncors;
                      void Start()

                      DragonAncors.GetComponent<DragonTracker>().GoldDragonInit = GoldDragonSpawn;







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 12 at 14:27









                      Karya SipahiKarya Sipahi

                      437




                      437























                          1














                          This is not valid c# code:



                          //get cariables from other script
                          DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                          Why? Because it isn't inside a method.



                          Also, the comment is wrong. It isn't getting a variable (typo, too), its setting a variable in another script!



                          The reason for the first...16 problems Visual Studio is complaining about are because of this line.



                          At this location you are only allowed to declare methods, fields, and properties and you're currently trying to access another class and change one of its members (something you can only do inside a method).



                          Additionally, you have .cs which I assume is because "DragonAnchors.cs is the file name!" which you don't need to do. I'm not sure how to go about rewriting this line (inside Start()) as I'm not sure what you're trying to actually do. That is, I don't know where an instance of DragonAnchors actually resides. You're calling GetComponent(), which is typically reserved for accessing components attached to game objects, but as you've attempted to do so on a static class reference, I'm not sure if you meant to call it on this or on something else.






                          share|improve this answer



























                            1














                            This is not valid c# code:



                            //get cariables from other script
                            DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                            Why? Because it isn't inside a method.



                            Also, the comment is wrong. It isn't getting a variable (typo, too), its setting a variable in another script!



                            The reason for the first...16 problems Visual Studio is complaining about are because of this line.



                            At this location you are only allowed to declare methods, fields, and properties and you're currently trying to access another class and change one of its members (something you can only do inside a method).



                            Additionally, you have .cs which I assume is because "DragonAnchors.cs is the file name!" which you don't need to do. I'm not sure how to go about rewriting this line (inside Start()) as I'm not sure what you're trying to actually do. That is, I don't know where an instance of DragonAnchors actually resides. You're calling GetComponent(), which is typically reserved for accessing components attached to game objects, but as you've attempted to do so on a static class reference, I'm not sure if you meant to call it on this or on something else.






                            share|improve this answer

























                              1












                              1








                              1







                              This is not valid c# code:



                              //get cariables from other script
                              DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                              Why? Because it isn't inside a method.



                              Also, the comment is wrong. It isn't getting a variable (typo, too), its setting a variable in another script!



                              The reason for the first...16 problems Visual Studio is complaining about are because of this line.



                              At this location you are only allowed to declare methods, fields, and properties and you're currently trying to access another class and change one of its members (something you can only do inside a method).



                              Additionally, you have .cs which I assume is because "DragonAnchors.cs is the file name!" which you don't need to do. I'm not sure how to go about rewriting this line (inside Start()) as I'm not sure what you're trying to actually do. That is, I don't know where an instance of DragonAnchors actually resides. You're calling GetComponent(), which is typically reserved for accessing components attached to game objects, but as you've attempted to do so on a static class reference, I'm not sure if you meant to call it on this or on something else.






                              share|improve this answer













                              This is not valid c# code:



                              //get cariables from other script
                              DragonAncors.cs.GetComponent.<DragonTracker>() GoldDragonInit = GoldDragonSpawn;


                              Why? Because it isn't inside a method.



                              Also, the comment is wrong. It isn't getting a variable (typo, too), its setting a variable in another script!



                              The reason for the first...16 problems Visual Studio is complaining about are because of this line.



                              At this location you are only allowed to declare methods, fields, and properties and you're currently trying to access another class and change one of its members (something you can only do inside a method).



                              Additionally, you have .cs which I assume is because "DragonAnchors.cs is the file name!" which you don't need to do. I'm not sure how to go about rewriting this line (inside Start()) as I'm not sure what you're trying to actually do. That is, I don't know where an instance of DragonAnchors actually resides. You're calling GetComponent(), which is typically reserved for accessing components attached to game objects, but as you've attempted to do so on a static class reference, I'm not sure if you meant to call it on this or on something else.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 8 at 22:00









                              Draco18sDraco18s

                              10.8k32242




                              10.8k32242





















                                  1














                                  This is how you can get to DragonTracker:



                                  DragonTracker dt = GameObject.Find("DragonAncores").GetComponent<DragonTracker>()
                                  Debug.Log(dt.DragonCount);





                                  share|improve this answer



























                                    1














                                    This is how you can get to DragonTracker:



                                    DragonTracker dt = GameObject.Find("DragonAncores").GetComponent<DragonTracker>()
                                    Debug.Log(dt.DragonCount);





                                    share|improve this answer

























                                      1












                                      1








                                      1







                                      This is how you can get to DragonTracker:



                                      DragonTracker dt = GameObject.Find("DragonAncores").GetComponent<DragonTracker>()
                                      Debug.Log(dt.DragonCount);





                                      share|improve this answer













                                      This is how you can get to DragonTracker:



                                      DragonTracker dt = GameObject.Find("DragonAncores").GetComponent<DragonTracker>()
                                      Debug.Log(dt.DragonCount);






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 9 at 11:01









                                      Gazihan AlankusGazihan Alankus

                                      1,92711418




                                      1,92711418





















                                          0














                                          There are a lot of errors there and they may take some steps to go through, but first things first you should clear up the issue with the code you're trying to use being unsupported. Go into the project settings and change the compiler language version as it notes on the 5th error down. This should allow you to use the newer functionality.






                                          share|improve this answer



























                                            0














                                            There are a lot of errors there and they may take some steps to go through, but first things first you should clear up the issue with the code you're trying to use being unsupported. Go into the project settings and change the compiler language version as it notes on the 5th error down. This should allow you to use the newer functionality.






                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              There are a lot of errors there and they may take some steps to go through, but first things first you should clear up the issue with the code you're trying to use being unsupported. Go into the project settings and change the compiler language version as it notes on the 5th error down. This should allow you to use the newer functionality.






                                              share|improve this answer













                                              There are a lot of errors there and they may take some steps to go through, but first things first you should clear up the issue with the code you're trying to use being unsupported. Go into the project settings and change the compiler language version as it notes on the 5th error down. This should allow you to use the newer functionality.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 8 at 15:56









                                              Ethan The BraveEthan The Brave

                                              257516




                                              257516



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066284%2fvariables-in-other-scripts-in-unity%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                                                  Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                                  2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived