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 StormTune19 · Dec 14, 2017 at 03:46 PM · c#gameobjectscripting beginner

Make an object appear during play

I have just finished completing the roll-a-ball tutorial for unity. I am currently having a problem with a GameObject and the count integer. I am attempting to add a little flair by making a ground piece appear upon collecting the first 12 pickups, yet do not know how to reference other scripts. ,I have just finished the learn tutorial for the roll-a-ball game and I am attempting to add a bit of flair to the project. For some reason I cannot place an int, namely count, on a GameObject, and as I am only doing tutorials so far I do not know how to reference other scripts. Once count reaches 12, I would like a cube or GameObject to appear so that the ball can escape the starting arena.

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

2 Replies

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

Answer by KittenSnipes · Dec 14, 2017 at 04:41 PM

So this should be your finished script:

     // Create public variables for player speed, and for the Text UI game objects
     public float speed;
     public Text countText;
     public Text winText;
 
     private float moveHorizontal;
     private float moveVertical;
 
     //This is a reference to the escape route object
     public GameObject escapeRoute;
 
     // Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
     private Rigidbody rb;
     private int count;
 
     // At the start of the game..
     void Start ()
     {
         // Assign the Rigidbody component to our private rb variable
         rb = GetComponent<Rigidbody>();
 
         // Set the count to zero 
         count = 0;
 
         // Run the SetCountText function to update the UI (see below)
         SetCountText ();
 
         // Set the text property of our Win Text UI to an empty string, making the 'You Win' (game over message) blank
         winText.text = "";
     }
 
     // Each physics step..
     void FixedUpdate ()
     {
         // Set some local float variables equal to the value of our Horizontal and Vertical Inputs
         moveHorizontal = Input.GetAxis ("Horizontal");
         moveVertical = Input.GetAxis ("Vertical");
 
         // Create a Vector3 variable, and assign X and Z to feature our horizontal and vertical float variables above
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         // Add a physical force to our Player rigidbody using our 'movement' Vector3 above, 
         // multiplying it by 'speed' - our public player speed that appears in the inspector
         rb.AddForce (movement * speed);
     }
 
     public float getHorizontal()
     {
         return moveHorizontal;
     }
 
     public float getVertical()
     {
         return moveVertical;
     }
 
     // When this game object intersects a collider with 'is trigger' checked, 
     // store a reference to that collider in a variable named 'other'..
     void OnTriggerEnter(Collider other) 
     {
         // ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
         if (other.gameObject.CompareTag ("Pick Up"))
         {
             // Make the other game object (the pick up) inactive, to make it disappear
             other.gameObject.SetActive (false);
 
             // Add one to the score variable 'count'
             count = count + 1;
 
             // Run the 'SetCountText()' function (see below)
             SetCountText ();
         }
     }
 
     // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
     void SetCountText()
     {
         // Update the text field of our 'countText' variable
         countText.text = "Count: " + count.ToString ();
 
         // Check if our 'count' is equal to or exceeded 12
         if (count >= 12) 
         {
             // Set the text value of our 'winText'
             winText.text = "You Win!";
 
             //Here after we win we enable the escape route to be visible for the player
             escapeRoute.SetActive(true);
         }
     }

You specifically only need this line in the function SetCountText as shown above:

 escapeRoute.SetActive(true);

Along with the reference to it at the very top of your code like this:

 public GameObject escapeRoute;

Here is a quick video showing the setup:

https://www.dropbox.com/s/4fk31fc6qkpfq90/RollABall.mp4?dl=0

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
avatar image
0

Answer by StormTune19 · Dec 15, 2017 at 03:25 PM

@KittenSnipes Thank you very much for your fast help, however I am still having a problem. I have implimented both pieces of code into PlayerController, i have created a cube named escapeRoute, and under WinText in the unity view of the PlayerController script i have made "Escape Route" bounded to said cube, yet when disabled, even while playing, upon collecting the 12th pick-up nothing happens. I very much appreciate the video help, but i did not see the code in action upon you collecting the 12th pick-up. I also realized that you did not have to bind any object to the script, but I have attempted t do so as no object named escapeRoute would appear if i were to place one.

In addition to this, have some error info. UnassignedReferenceException: The variable escapeRoute of PlayerController has not been assigned. You probably need to assign the escapeRoute variable of the PlayerController script in the inspector. PlayerController.SetCountText () (at Assets/_Completed-Game/Scripts/PlayerController.cs:84) PlayerController.OnTriggerEnter (UnityEngine.Collider other) (at Assets/_Completed-Game/Scripts/PlayerController.cs:68)

I have no idea what any of this means being a beginner and all, so your additional help would be gladly appreciated.

Comment
Add comment · Show 9 · 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 KittenSnipes · Dec 15, 2017 at 03:28 PM 0
Share

@StormTune19 $$anonymous$$ay I see how you implemented it? I will help in any way I can

avatar image StormTune19 KittenSnipes · Dec 15, 2017 at 03:30 PM 0
Share

I placed both pieces of code in the exact places you have shown up above.

avatar image KittenSnipes StormTune19 · Dec 15, 2017 at 03:32 PM 0
Share

Ok well then you need to place the gameObject which is your escape route in to the assigned spot under player controller. So click on your player and drag it into that empty spot in the script.

avatar image KittenSnipes · Dec 15, 2017 at 03:30 PM 0
Share

@StormTune19

If needed I can email you my skype so I can more personally help you. Only if you wish

avatar image StormTune19 KittenSnipes · Dec 15, 2017 at 03:32 PM 0
Share

Don't have skype, this is all i have for now

avatar image KittenSnipes StormTune19 · Dec 15, 2017 at 03:33 PM 0
Share

I will just show you the whole setup via video then

Show more comments
avatar image KittenSnipes · Dec 15, 2017 at 03:46 PM 0
Share

@StormTune19

Here is the new video showing what to do with the escape route:

https://www.dropbox.com/s/yg07wfx3fy9jc05/AddingTheEscapeRoute.mp4?dl=0

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

435 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 make a game object grow by absorbing another game object ? 0 Answers

Possible Infinite Loop Freezing Game 1 Answer

Beginner needs Help! 1 Answer

¿Does AudioListener.volume save for all scenes? 0 Answers

Why won't my model rotate up on X axis? 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