Tried to search for help write/edit a script for pickup. I have 3 different items with different points, but when i’m trying collecting one item the points for every item gets added on the score for each, so 1 item = 6 points. I see that i probably must add some if else statements, but when i try i either looses sound (it’s a different sound for each item,), have the same problem or it’s not working at all. Can i please get some input on how to manage this?
using UnityEngine;
using System.Collections;
public class pickup : MonoBehaviour {
public int PointOneValue;
public int PointTwoValue;
public int PointThreeValue;
private bool _triggered;
private AudioSource _lydkilde;
// Use this for initialization
void Awake ()
{
PointOneValue = 1;
PointTwoValue = 2;
PointThreeValue = 3;
_lydkilde = gameObject.GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (_triggered !_lydkilde.isPlaying)
Destroy(gameObject);
}
// On sound the score get's updated.
void OnTriggerEnter()
{
_triggered = true;
_lydkilde.enabled = true;
Spillet.PickUpCount += PointOneValue;
Spillet.PickUpCount += PointTwoValue;
Spillet.PickUpCount += PointThreeValue;
}
}