• 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 Cosmology27 · Jul 16, 2019 at 07:16 PM · transformfindobjectoftype

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!

Comment
Add comment · Show 1
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 Vega4Life · Jul 18, 2019 at 05:41 PM 1
Share

if (findEnemy = null)

should be:

if (findEnemy == null)

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

210 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 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

OnTriggerEnter doesn't work if the colliding object is not moving. Translating it by (0,0,0) fixes it. What's the problem? 4 Answers

Combining local coordinates into world coordinates. 0 Answers

Drag Object with Touching 0 Answers

How do you maintain gravity using transform.forward and transform.right? 0 Answers

Can't move instantiated object. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges