Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ColonelOmen · Sep 29, 2017 at 08:21 AM · objectinspectorvariablesvalues

Values from another script not assigning to variable

I have 4 monsters that each have a script called EnemyBattle that holds their stats. I have another script called BattleManager that gets their stats and assigns them to another variable on Awake. This was working perfectly fine for awhile but then out of nowhere the values for all but one of the monsters aren't getting assigned to the variables. I fixed this issue the first time by deleting the objects that were giving me the issue and duplicating the single monster that was returning it's stats but now I have the same issue again but with only 2 of them. I don't ever recall doing anything in the inspector to the GameObjects so I have no clue why this is happening and I have to assume it's a bug. I've tried restarting Unity but that still didn't work. Here's the code for reference:

 void Awake {
     enemy1 = GameObject.Find("Dragon_1");
     enemy2 = GameObject.Find("Dragon_2");
     enemy3 = GameObject.Find("Dragon_3");
     enemy4 = GameObject.Find("Dragon_4");
 
     EnemyBattle eb1 = enemy1.GetComponent<EnemyBattle>();
     EnemyBattle eb2 = enemy2.GetComponent<EnemyBattle>();
     EnemyBattle eb3 = enemy3.GetComponent<EnemyBattle>();
     EnemyBattle eb4 = enemy4.GetComponent<EnemyBattle>();
 
     espeed1 = eb1.GetSpeed();
     espeed2 = eb2.GetSpeed();
     espeed3 = eb3.GetSpeed();
     espeed4 = eb4.GetSpeed();
 }

Before it would only get the speed for enemy4 but now it gets the speed for only enemy1 and enemy4.

I also have an Animator connected to each enemy and call their animations just fine.

Here's what it looks like in the inspector

alt text

I can probably just delete them and duplicate again but I would like to avoid this problem or at least identify it if I can so can someone please help me?

untitled.png (1.8 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ColonelOmen · Oct 07, 2017 at 09:13 AM 0
Share

Does anyone have an answer? I still can't figure out why it does this. It even happens when I build the game and it's very problematic. Should also add that I have another script that gets their speed just fine so I guess something must be wrong with this one?

avatar image ColonelOmen · Oct 07, 2017 at 09:41 AM 0
Share
 public class EnemyLaneTrigger : $$anonymous$$onoBehaviour
 {
     public string name;
     public int speed = 0;
 
     public GameObject enemy1 = null;
     public GameObject enemy2 = null;
     public GameObject enemy3 = null;
     public GameObject enemy4 = null;
 
     public int espeed1;
     public int espeed2;
     public int espeed3;
     public int espeed4;
 
     void Start ()
     {
         enemy1 = GameObject.Find("Dragon_1");
         enemy2 = GameObject.Find("Dragon_2");
         enemy3 = GameObject.Find("Dragon_3");
         enemy4 = GameObject.Find("Dragon_4");
 
         EnemyBattle eb1 = enemy1.GetComponent<EnemyBattle>();
         EnemyBattle eb2 = enemy2.GetComponent<EnemyBattle>();
         EnemyBattle eb3 = enemy3.GetComponent<EnemyBattle>();
         EnemyBattle eb4 = enemy4.GetComponent<EnemyBattle>();
 
         espeed1 = eb1.Speed;
         espeed2 = eb2.Speed;
         espeed3 = eb3.Speed;
         espeed4 = eb4.Speed;
 
     }
 public class Battle$$anonymous$$anager : $$anonymous$$onoBehaviour 
 {
     public int eSpeed1;
     public int eSpeed2;
     public int eSpeed3;
     public int eSpeed4;
         public GameObject enemy1 = null;
     public GameObject enemy2 = null;
     public GameObject enemy3 = null;
     public GameObject enemy4 = null;
         void Start ()
     {
         enemy1 = GameObject.Find("Dragon_1");
         enemy2 = GameObject.Find("Dragon_2");
         enemy3 = GameObject.Find("Dragon_3");
         enemy4 = GameObject.Find("Dragon_4");
 
         EnemyBattle eb1 = enemy1.GetComponent<EnemyBattle>();
         EnemyBattle eb2 = enemy2.GetComponent<EnemyBattle>();
         EnemyBattle eb3 = enemy3.GetComponent<EnemyBattle>();
         EnemyBattle eb4 = enemy4.GetComponent<EnemyBattle>();
 
         eSpeed1 = eb1.Speed;
         eSpeed2 = eb2.Speed;
         eSpeed3 = eb3.Speed;
         eSpeed4 = eb4.Speed;
 
     }
 

EnemyLaneTrigger gets the speeds just fine but Battle$$anonymous$$anager won't

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GPSGAME · Jun 30, 2020 at 05:15 PM

@ColonelOmen I am trying to make a game similar like yours. did u get the solution. please share it

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dragging an object to variable: Problems in the editor! 2 Answers

How to Access Values from a Object,How to access values from a object 0 Answers

scripting problems please help 0 Answers

I removed a variable from my script but it still shows up in the inspector,I removed a public int from my script yet it stills shows up in the inspector when looking at the script component 2 Answers

Why is my value of a variable playerpref always the same? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges