- Home /
Problem with adding number of Potions
I have a script to when i pickup the gameobjet with this script, it add 1 potion to my player, but i don't know why, it's adding 2 potions no matter how i change the value, it add always 2.
using UnityEngine;
using System.Collections;
public class PotionPickup : MonoBehaviour {
public int potionUp = 1;
void Start(){
}
void OnTriggerEnter (Collider other) {
if (!other.CompareTag("Player")) return;
FireButton.potion += potionUp;
Destroy (gameObject);
}
}
I don't know why but it is multiplying the value, if i set potionUp to 3, it give me 6,12,18.
Answer by MakeCodeNow · Feb 15, 2014 at 04:26 PM
It sounds like your OnTriggerEnter is getting called twice in one frame. Does your player have multiple colliders on it? I bet that (or something similar) is the problem. If so, you'll need to add a flag to your component like "already used" and check that in OnTriggerEnter.
i think that could be the problem, i will see that.
Thanks, you saved my day, the problem was, that i placed a tag of player on my main character object, for some reason, every child got this tag, so my gun with collider got player tag
No prob! Please accept my answer so that others know this is resolved.
Accepted, i'm new here so i'm still learning how to do things XD, finally i found the Accept button that makes everything GREEN! Thanks man, you rock!