Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by mgadth · Feb 23, 2014 at 09:07 PM · c#errortransformpositionif-statements

If gameobject moves do this

I am trying to have one gameobject set active upon another gameobject moving beyond its current position in the y axis. Please help if you can. Getting a "Missing Field Exception: System.Boolean.transform" error. Whatever that means. See code below. Please help. Thanks.

function Update (){ if ((gameObject.tag == "door").transform.position.y > 1){ doorlight.SetActive(true); } }

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 getyour411 · Feb 23, 2014 at 09:08 PM 0
Share

For this and future posts, please use the 101010 button to format your code.

You are taking a Boolean condition if(condition) and trying to tack on a .transform.position which isn't valid syntax. Refactor that.

avatar image locrian05 · Feb 23, 2014 at 09:10 PM 2
Share

I suggest learning how to code properly first.. try this http://unity3d.com/learn/tutorials/modules/beginner/scripting

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RudyTheDev · Feb 23, 2014 at 09:20 PM

What you need to do is very roughly:

 public class YourClass : MonoBehaviour
 {
     public GameObject doorlight; // drag&drop this in inspector
 
     private GameObject door; // we will find this (or could make it public and also drag&drop in inspector, then Start() isn't needed)
 
     function Start()
     {
         door = GameObject.FindWithTag("door"); // find the door - game object with door tag
     }
 
     function Update()
     {
         if (door.transform.position.y > 1)
         {
             doorlight.SetActive(true);
         }
     }    
 }

Question is, how you actually want to define, initialize and access your door. You gave very little detail about your game and what door or light are and how you access them.

Comment
Add comment · Show 4 · 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
avatar image mgadth · Feb 23, 2014 at 11:52 PM 0
Share

Yea, I am learning. This is all slowly starting to make sense. It seems as though you were writing in "C", and not Javascript but since they seem so similar I was able to figure out where I was wrong based on what you provided. You were super helpful. Thank you so much!!!

I needed to make a door variable, which I didn't have, and assign my game object "door" to it in the inspector. Have it accessed in the start function as you showed me, then have the update function do its thing with if (door means this) {then do this}. Also needed to tweak the y units from 1 to 50 to be effective. I already had a separate script moving the door.

Again Thank you. Very helpful.

avatar image Linus · Feb 23, 2014 at 11:53 PM 0
Share

Converted your answer into a comment.

avatar image RudyTheDev · Feb 24, 2014 at 09:13 AM 0
Share

@mgadth: Oh, whoops, my bad. I copy-pasted and missed the function while the rest was the same for both languages. I guess $$anonymous$$e is pseudo-code then :) Glad it at least helped. P.S. You can mark the answer as accepted to "close" the question.

avatar image mgadth · Feb 24, 2014 at 07:35 PM 0
Share

Thanks! I'm new at the forum too. The tutorial is not functioning, lol.

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

23 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

Related Questions

stop object(door) translation 0 Answers

C# the position of the object 1 Answer

Freeze transform.rotation.x 1 Answer

Why are floats not accessing my inputted values? 1 Answer

Obtaining the relative size of a Models body part 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