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 kyeoreheo · May 07, 2016 at 01:23 AM · booleanmovinggameobject

Make object move with Bool C#

my goal is make my spike move Up and Down when the bool is checked. But if i run? no matter what, it turned to True, and start to going down!!! I didnt even checked it. Please help me...!

using UnityEngine; using System.Collections;

public class MovingSpike : MonoBehaviour

{

 public GameObject spike;
 public float moveSpeed;
 public Transform spikeUp;
 public Transform spikeDown;
 public bool moving;

 void Update () 
 {
     if (moving = false) 
     {
         spike.transform.position = Vector3.MoveTowards (spike.transform.position, spikeUp.transform.position, Time.deltaTime * moveSpeed);
     }
     if (moving = true) 
     {
         spike.transform.position = Vector3.MoveTowards (spike.transform.position, spikeDown.position, Time.deltaTime * moveSpeed);

     } 
 }

}

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 TBruce · May 07, 2016 at 01:38 AM 0
Share

@kyeoreheo

@jgodfrey is correct. But even better would be

 if (!moving)
 {
     spike.transform.position = Vector3.$$anonymous$$oveTowards (spike.transform.position, spikeUp.transform.position, Time.deltaTime * moveSpeed);
 }
 else
 {
     spike.transform.position = Vector3.$$anonymous$$oveTowards (spike.transform.position, spikeDown.position, Time.deltaTime * moveSpeed);
 } 

But it is still the same as @jgodfrey's answer.

avatar image jgodfrey TBruce · May 07, 2016 at 01:42 AM 0
Share

Absolutely agree. Didn't want to go there...

1 Reply

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

Answer by jgodfrey · May 07, 2016 at 01:33 AM

At the very least, this...

 if (moving = false) 

and this...

 if (moving = true) 

Should be:

 if (moving == false) 

and...

 if (moving == true) 
Comment
Add comment · Show 3 · 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 kyeoreheo · May 07, 2016 at 01:36 AM 0
Share

oh my god.... i was trying to other way to solve this for a day.

By the way.. why it is "==" not "="

avatar image TBruce kyeoreheo · May 07, 2016 at 01:41 AM 0
Share

" = " is an assignment

" == " this is a comparison.

avatar image jgodfrey · May 07, 2016 at 01:39 AM 0
Share

Using "=" assigns a a value to something. For instance:

 int a = 1;

assigns the value "1" to the variable "a".

"==" tests for equality between two things. For instance:

 if (a == 1)

tests if variable "a" is equal to the value of "1".

Assu$$anonymous$$g your question is answered, please accept the answer.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why doesn't the collider work? 1 Answer

how to keep an animation condition after Application.loadLevel 0 Answers

If statement not working 1 Answer

how do i change a bool from a script in a different game object c# 1 Answer

i need help with bollean 2 Answers


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