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 mrsam993 · Oct 05, 2017 at 10:48 PM · componentboolean

Referencing non-static variables

I'm making a basic basket ball game and i have a public boolean called dunkComplete which activated after the ball is dunked and is attaced to the ball script, i am trying to reference this boolean in a game manager script but for some reason even though dunkComplete becomes true its game manager counterpart doesn't, heres the game manager script for reference.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class game_manager : MonoBehaviour {

     public GameObject Basket;

     private float x_value;
     private float y_value;

     public GameObject ball;
     private ball_script basketBallScript;
     private bool dunkCompleteOperation;

     // Use this for initialization
     void Start () {
         basketBallScript = ball.GetComponent<ball_script>();

         Vector2 randomVector = new Vector2(Random.Range(-9f, 9f), Random.Range(0f, 3f));

         Debug.Log(randomVector);

         Instantiate(Basket, randomVector, transform.rotation);

         Instantiate(ball, new Vector2(0, -3.5f), transform.rotation);
     }
 
     // Update is called once per frame
     void Update () {

         dunkCompleteOperation = basketBallScript.dunkComplete;

         if (dunkCompleteOperation == true)
         {
             Vector2 randomVector = new Vector2(Random.Range(-9f, 9f), Random.Range(0f, 3f));

             Instantiate(Basket, randomVector, transform.rotation);
         }
     }
 }


Any help would be greatly apreciated thanks.

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 Caruzo · Oct 05, 2017 at 11:06 PM 0
Share

Could you post the ball script as well?

avatar image mrsam993 Caruzo · Oct 06, 2017 at 05:16 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class ball_script : $$anonymous$$onoBehaviour {

     public Rigidbody2D rb;

     public float force = 5f;
     public float torque = 0.1f;

     private Vector2 startSwipe;
     private Vector2 endSwipe;

     private float x_swipe;

     public float dunkTime;
     private float tempDunkTime;
     private bool dunked;
     public bool dunkComplete;

     // Use this for initialization
     void Start ()
     {
         rb.velocity = new Vector2(0, 0);
         dunkComplete = false;
         dunked = false;
         rb.is$$anonymous$$inematic = true;
         tempDunkTime = dunkTime;
     }
 
     // Update is called once per frame
     void Update ()
     {
         if (Input.Get$$anonymous$$ouseButtonDown(0))
         {
             startSwipe = Camera.main.ScreenToViewportPoint(Input.mousePosition); 
         }
         if (Input.Get$$anonymous$$ouseButtonUp(0))
         {
             endSwipe = Camera.main.ScreenToViewportPoint(Input.mousePosition);
             Swipe();
         }

         if (dunked == true)
         {
             tempDunkTime -= Time.deltaTime;
         }
         if (0 > tempDunkTime)
         {
             dunkComplete = true;
             //set ball position move to game manager
             //rb.velocity = new Vector2 (0, 0);
             //transform.position = new Vector2(0, -3.5f);
             //rb.is$$anonymous$$inematic = true;
             //dunked = false;
             //tempDunkTime = dunkTime;
             //dunkComplete = false;
         }
     }

     void Swipe ()
     {
         rb.is$$anonymous$$inematic = false;

         Vector2 swipe = endSwipe - startSwipe;

         swipe = swipe * force;

         x_swipe = swipe.x;
         x_swipe = x_swipe * -1;

         Debug.Log(swipe);

         rb.AddForce(swipe, Force$$anonymous$$ode2D.Impulse);
         rb.AddTorque(x_swipe*torque, Force$$anonymous$$ode2D.Impulse);
     }

     void OnTriggerEnter2D(Collider2D col)
     {
         if(col.tag == "Finish")
         {
             dunked = true;
             //rb.is$$anonymous$$inematic = true;
         }
     }
 }

There it is

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mrsam993 · Oct 07, 2017 at 08:24 PM

If anybody else has this problem i found the solution here http://answers.unity3d.com/questions/418609/how-do-i-check-if-bool-is-true-from-another-script.html

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

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

117 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

Related Questions

How to set a bool from a script equal to another bool from another script? 1 Answer

On Trigger Exit Help 1 Answer

Movement sometimes not working 1 Answer

Make bools on one script exclusive to that script and not other scripts of the same type 0 Answers

RigidBody2D not working right. Help! 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