Help with finding object and transform values
Very sorry for formatting. I've never had this problem on a forum before, I don't know why it's doing this, or how to fix it. Sorry again!
Two questions:
So I've got a bunch of enemies with a script "AccelerateTowards" on them all. I made a transform variable called "findEnemy", and it's telling me it never gets called, even though it's OBVIOUSLY being called further down in the void update. What I'm doing is, I'm resetting the value of findEnemy to null, then asking the game to find any objects with the script "AccelerateTowards" in it (which will only be the enemies). If there are no enemies, I would think the variable would get the result of null, right? Or at the very least, the value wouldn't be updated, so it would stay as null, right? Anyways, the if statement never triggers, because the level never resets. My question is just why doesn't this work? Here's what I got:
findEnemy = null;
findEnemy = FindObjectOfType<AccelerateTowards>().transform;
if (findEnemy = null)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
I then thought to try and make an empty rigidbody at 0,0,0 with the same script (AccelerateTowards) so that the value brought back for findEnemy when there are no enemies would be 0,0,0. Then, I made this "if (findEnemy = (0, 0, 0))" with the result being a scene reset. This STILL says the findEnemy is being read (when it obviously is), and it says I cannot implicity convert type (int,int,int) into a UnityEngine.Transform. This is my second question; how do I assign a transform value to a transform object? I thought they received an (x,y,z) value? Why isn't it accepting it?
I'm sure it's just me not understanding something, because I'm quite new. Thanks for any help you can provide!
if (findEnemy = null)
should be:
if (findEnemy == null)
Your answer
![](https://koobas.hobune.stream/wayback/20220612205000im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Applying two independent rotations 0 Answers
Animation does not move! 2 Answers
Animation of an obgect transform according to it's change 1 Answer
fill public Transform[] on Awake? 1 Answer
Unity Networking(old) Question.(Teleporting player) 1 Answer