• 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 eugenekim2727 · Nov 12, 2020 at 04:32 PM · collision detectionslideroncollisionenterboxcolliderprogress-bar

How to make a progress bar go up after two objects collide?

So I have a progress bar but I would like to know how to make it fill up after my player finishes a task. The idea would be for the player to put objects into other objects (example food into a dog bowl). Here is my entire progress bar script which I got after following along DevDuck's tutorial on progress bars.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events;

public class ProgressBar : MonoBehaviour { private Slider slider;

 public float FillSpeed = 0.5f;

 private float targetProgress = 0;
 

 
 private void Awake()
 {
     slider = gameObject.GetComponent<Slider>();
 }

 // Start is called before the first frame update
 void Start()
 {
     IncrementProgress(.00f);
 }

 // Update is called once per frame
 void Update()
 {
     if (slider.value < targetProgress)
         slider.value += FillSpeed * Time.deltaTime;
 }


 public void IncrementProgress(float newProgress)
 {
     targetProgress = slider.value + newProgress;
     
 }

 void OnCollisionEnter(Collision col){
     if(col.gameObject.tag == "dog Bowl"){
         IncrementProgress(.5f);}
     if(col.gameObject.tag == "dishwasher"){
         IncrementProgress(.25f);}
     if(col.gameObject.tag == "dishwasher"){
         IncrementProgress(.25f);}
 }

}

The part at the end was my attempt at getting Unity to recognize a collision and fill up the progress bar after detecting the collision. THANKS!

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

143 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

Related Questions

How to Make a progress bar go up after two objects collide. 1 Answer

Slider with negative and positive values 1 Answer

Why does OnCollisionEnter not work between a character controller and a rigidbody? 3 Answers

BoxCollider get stuck when dragging over the border of two BoxColliders 1 Answer

Help with collisions and destroy please 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges