I’ve got a problem. in my project there are 2 different scripts for adding. One adds points when you pickup coins and the other adds on time when you pickup a timeobject. But, when the character collects coins he gets both points and extra time. When he collects time-object he only gets extra time. But why? I’ve tried several ways but…, Hope someone has a input on why this happens?
Add time script. i’ve checked that the only object marked with the tag “ExtraTime” is the right object.
using UnityEngine;
using System.Collections;
public class EkstraTid : MonoBehaviour {
Tid tid;
int intTid;
// This method gives access to the timecomponent in the game
void Start ()
{
GameObject spillet = GameObject.Find ("Spillet");
tid = spillet.GetComponent<Tid>();
}
// when entering into gameObject EkstraTid extra time is added to the timecomponent in the game
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("ExtraTime"))
Destroy(other.gameObject);
tid.tiden += 100f;
}
}
This is the script adding points.
using UnityEngine;
using System.Collections;
public class pickupvs3 : MonoBehaviour {
public int CoinValue;
private bool _triggered;
private AudioSource _lydkilde;
// Use this for initialization
void Awake ()
{
_lydkilde = gameObject.GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (_triggered !_lydkilde.isPlaying)
Destroy(gameObject);
}
// When audio is playing the coin is triggered, points are given. Pointvalue chosen in the inspector
void OnTriggerEnter()
{
_triggered = true;
_lydkilde.enabled = true;
Spillet.PickUpCount += CoinValue;
gameObject.GetComponent<MeshRenderer>().enabled = false;
}
}