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 /
This question was closed Jul 05, 2019 at 05:06 AM by MHF7517.
avatar image
0
Question by MHF7517 · Jun 25, 2019 at 05:04 AM · unity 5return value

wrong return

Hi guys....I have a problem with with a return in my code... this is my code....everything is okay but CoinMove method doesn't return 1 and return 0.... my code is in the pic

public class Cube : MonoBehaviour { [SerializeField] float xVelocitySpeed = 5f; [SerializeField] float yVelocitySpeed = 0f; Rigidbody2D cubeRigidbody;

 [SerializeField] GameObject cubeStarterPrefab;
 [SerializeField] float cubeDelayToMove;

 private bool ImIn = false;
 public int CoinsPlusOne = 0;

 // Start is called before the first frame update
 void Start()
 {
     cubeRigidbody = GetComponent<Rigidbody2D>();
     CoinMove();
 }

 // Update is called once per frame
 void Update()
 {       
     Invoke("MoveCubes", cubeDelayToMove);
     //if (Input.GetButtonDown("Fire1"))
     //{
     //    analyzer();
     //}
     analyzer();
 }

 public void MoveCubes()
 {
     cubeRigidbody.velocity = new Vector2(xVelocitySpeed, yVelocitySpeed);
 }

 void OnTriggerEnter2D(Collider2D wall)
 {
     if(wall.name == "in")
     {
         ImIn = true;
     }
     else if(wall.name == "out")
     {
         ImIn = false;
     }
     else
     {
         DestroyObject(gameObject);
     }    
 }

 public void analyzer()
 {
     if(ImIn == true && gameObject.tag == "WhiteCubes")
     {
         CoinsPlusOne += 1;
         ImIn = false;
     }     
     else if(ImIn == true && gameObject.tag != "WhiteCubes")
     {
         return;
     }
     else
     {
         return;
     }
 }
   
 public int CoinMove()
 {
     return CoinsPlusOne;
 }

}

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 MHF7517 · Jun 25, 2019 at 05:07 AM 0
Share

I use Coin$$anonymous$$ove somewhere else and return 0

avatar image xxmariofer MHF7517 · Jun 25, 2019 at 07:26 AM 0
Share

add a debug.log() in coinmove and in the analyzer and check whats getting called before

1 Reply

  • Sort: 
avatar image
0

Answer by ChrisD0 · Jun 25, 2019 at 10:22 AM

It is the if statement in the analyzer that increments CoinsPlusOne. But look at the condition; and gameObject.tag == "WhiteCubes". When you use gameObject in code, it references the object that the script is attached to. Are you trying to use it to check the tag of the object that was collided with?

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

204 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

Related Questions

How do I reference an incremented int with one button, that was incremented from another button? 1 Answer

Player controls and UI Controls don't work together in the same scene 0 Answers

Getting crash on specific devices? 0 Answers

MLAGENTS: Is it possible to omit a failed agent's data from learning model? 0 Answers

On collision with enemy slow player down while inside the collision box, else normal speed. 0 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