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 El-Deiablo · May 30, 2016 at 10:11 PM · pointspowerupdouble

Double Points Powerup

I am trying to make a double points powerup and am really close to figuring it out! I created a multiplier in my scoremanager and set it equal to one. When the player collides with the X2 object the multiplier is incremented by 1 (multiplier++). My code works briefly, but then the score starts getting ridiculously high. I decremented the multiplier (multiplier--) after the powerup duration is finished, but that does not seem to work. I would appreciate any help.

Here my code:

Code1:

 using UnityEngine;
 using System.Collections;
 
     public class Multiplier : MonoBehaviour {
 
         public GameObject particle;
         public AudioClip powerUpSound;
         public float time;
     bool Active=false;
 
     void Update(){
 
         if (Active==false) {
             StartCoroutine (DestroyGameObject ());
         }
     }
 
         IEnumerator ScoreMultiplier(){
         
             Active = true;
             ScoreManager .multiplier ++;
             yield return new WaitForSeconds (time);
             ScoreManager.multiplier--;
             Destroy (gameObject);
 
         }
 
     IEnumerator DestroyGameObject(){
 
         yield return new WaitForSeconds (3);
         gameObject.GetComponent <SpriteRenderer > ().enabled = false;
         yield return new WaitForSeconds (17);
         Destroy (gameObject);
 
     }
 
         void OnTriggerEnter2D(Collider2D other){
 
             if (other.tag == "Player") {
 
                 Active = true;
 gameObject.GetComponent <SpriteRenderer > ().enabled = false;
                 StartCoroutine (ScoreMultiplier ());
 }
 
 }
 
 }

Code 2 (Attached to player):

 using UnityEngine;
 using System.Collections;
 using UnityEngine .Audio ;
 using UnityEngine .SceneManagement ;
 
 public class Player : MonoBehaviour {
 
 private int Base_Reward1=100;
     private int Base_Reward2=200;
     private int Base_Reward3=300;
 
 public void OnTriggerEnter2D(Collider2D  other){
         
         if (other.tag == "Running Player1") {
 
             ScoreManager.scoreCount += Base_Reward1*=ScoreManager .multiplier;
 Destroy (other.gameObject);
 
 }
 
 }
 
 }


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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Alec-Slayden · May 31, 2016 at 08:10 PM

It looks like you might be destroying the score object before it has a chance to decrease the multiplier again.

if I understand correctly, when the player collides with the bonus trigger, the bonus hides its sprite, increases the multiplier, then begins to wait for a little while before decreasing the multiplier and self-destructing.

however, in the player script, you destroy the bonus game object immediately, so that coroutine will stop before it has a chance to decrease the multiplier.

Consider using OnDestroy() to clear the bonus.

Comment
Add comment · Show 1 · 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 El-Deiablo · May 31, 2016 at 09:11 PM 0
Share

Thanks for getting back to me.

I should have been a little more clear in my description. The "Running Player1" object is not the powerup. When the player collides with the powerup the points earned are increased. Even when the powerup is not active the player will receive points when colliding with the "Running Player1." When I destroy the gameObject in the Player script it is not the powerup that I am destroying, but the "Running Player1." I don't think destroying this gameObject is the issue, but I could be wrong.

I just noticed something in my Player script (line 16) - Score$$anonymous$$anager.scoreCount += Base_Reward1*=Score$$anonymous$$anager .multiplier;

I should have it like this: Score$$anonymous$$anager.scoreCount += (Base_Reward1*Score$$anonymous$$anager .multiplier);

In the original code I did *= which would help clarify why the score was reaching an absurd amount. Won't be able to test until tonight. Hopefully this small error will fix the issue.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

PowerUp Tutorials 1 Answer

Scoring only one or zero in one InputField? 0 Answers

Find if a gameObject is between two points while rotating in 2d,Find if a gameObject is between two points while rotating 0 Answers

Spawn power ups after random amount of time 1 Answer

how to convert depth image into 3D point cloud in Unity or HoloLens? 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