- Home /
Coins Multiplier
I want to make a power up trigger where the trigger will multiply the coin by 2 if i collect the coins for 5 seconds. Below is my coin script.
using UnityEngine; using System.Collections;
public class CoinBehavior : MonoBehaviour {
public int value;
// Use this for initialization
void OnTriggerEnter()
{
CoinManager.instance.Collect(value, gameObject);
AudioSource source = GetComponent<AudioSource>();
source.Play();
}
}
And this is the coin manager script
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class CoinManager : MonoBehaviour {
public static CoinManager instance = null;
public GameObject scoreTextObject;
int score;
Text scoreText;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != null)
Destroy(gameObject);
scoreText = scoreTextObject.GetComponent<Text>();
scoreText.text = "Score: " + score.ToString();
}
public void Collect(int passedValue, GameObject passedObject)
{
passedObject.GetComponent<Renderer>().enabled = false;
passedObject.GetComponent<Collider>().enabled = false;
Destroy(passedObject, 1.0f);
score = score + passedValue;
scoreText.text = "Score: " + score.ToString();
}
}
Can someone help me with the power up script. Thank You ^.^v
Comment
Your answer
Follow this Question
Related Questions
Coin Multiplier Power-up using three objects -- Need Help! 0 Answers
Switch Levels After Getting A Score? 2 Answers
Problem with collectable item counter and triggers 1 Answer
Collecting objects? 1 Answer
Collecting 2 items at a time by mistake. 0 Answers