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 /
avatar image
0
Question by BuzzardRaze765 · Jan 03, 2019 at 10:39 AM · booleanconditionexpressionstatements

I can't move my spawned ball after i put Else If statement

i have a script, but i've got major problem.i was making a color game, and here's the script for the player:

 public class BallMovementYellow : MonoBehaviour {
 
     public float speed = 0.5f;
     public float camLimitX;
     Rigidbody BallRB;
     public GameManager GameStatus;
     public static bool hasStopped;
     public GameObject EndPanel;
     public float DestroyTime = 1f;
 
     // Use this for initialization
     void Start () {
         hasStopped = false;
         EndPanel.SetActive (false);
     }
     
     // Update is called once per frame
     void Update () {
         FallMovement ();
     }
 
     void FallMovement(){
         if (hasStopped == false) {//while game is still running
             Vector3 myPos = transform.position;
             myPos.x = Mathf.Clamp (myPos.x, -camLimitX, camLimitX);
             float h = CrossPlatformInputManager.GetAxis ("Horizontal");
             transform.Translate (h * speed, 0, 0);
 
         }
     }
         
     void OnTriggerEnter(Collider other){
         if (other.gameObject.name =="Yellow") {//Collide to same Color
             Destroy (gameObject);
             ScoreText.ScoreValue += 1;
         }/*else if (other.gameObject.name != "Yellow"){//Collide to different Color
             hasStopped = true;
             FindObjectOfType<GameManager>().EndTheGame();
             EndPanel.SetActive(true);
         }*/
     }
 
 }

The Problem is that, everytime it spawn, it can't move, as it looks like it fulfills the Else If Statement. that's why i just hid the Else If Statement Here's the Ball Spawning script

 public float rate;
     public GameObject[] PlayerBall;
     public int wave;
 
     // Use this for initialization
     void Start () {
         InvokeRepeating ("Spawning", rate, rate);
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void Spawning(){
         for (int i = 0; i < wave; i++) {
             Instantiate (PlayerBall [(int)Random.Range (0, PlayerBall.Length)], new Vector3 (Random.Range (-4,4),9,0), Quaternion.identity);
         }
     }
 }

Can Anyone Help me out? i still created these script with my basic coding understanding and translation skill.

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 Ady_M · Jan 04, 2019 at 12:28 AM 0
Share

Try debugging the object it collided with. Don't forget to Collapse/Uncollapse the console messages as needed.

 void OnTriggerEnter(Collider other) {
     Debug.Log (other.gameObject.name);
     return; // Skips the rest of the code
     
     // (Rest of your code)
 }

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.

Follow this Question

Answers Answers and Comments

100 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

Related Questions

Multiple conditions 2 Answers

Delay something until no object has a certain condition 2 Answers

Why is door opening so fast with boolean condition? 0 Answers

How to optimize if statements - can't remember term 1 Answer

c# Disregards my bool as if it doesn't exist? 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