Here is my script
function Update () {
if(clickToDrink == true && readyToDrink == true && Input.GetMouseButton(0)) {
pickedUp = true;
}
readyToDrink = recogniserObject.transform.gameObject.GetComponent(recogniser).readyToDrink;
if(pickedUp == true) {
Drink ();
}
}
function player1Drunk () {
gameObject.Find("Player1").GetComponent(Player1).drunkness++;
}
function player2Drunk () {
gameObject.Find("Player2").GetComponent(Player2).drunkness++;
}
function Drink () {
var step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, cupPosition.position, step);
if(gameObject.transform.position == cupPosition.transform.position) {
gameObject.transform.position = cupPosition.transform.position;
//transform.rotation.x = -0.2;
yield WaitForSeconds (2);
if(gameObject.tag == "P1cups") {
gameObject.Find("PongBall").GetComponent(BallShooting).drinkFirstP1 = false;
player1Drunk ();
}
if(gameObject.tag == "P2cups") {
gameObject.Find("PongBall").GetComponent(BallShooting).drinkFirstP2 = false;
player2Drunk ();
}
yield WaitForSeconds (0.1);
GetComponent.<Rigidbody>().AddForce (10, 0, 0);
pickedUp = false;
GetComponent.<Rigidbody>().isKinematic = false;;
GetComponent.<BoxCollider>().isTrigger = false;
readyToDrink = false;
zeroGravityThing.gameObject.SetActive(true);
So i took the part of the script that i use for this. Sorry if its a little messy.
But what it does is: If i click on a cup, the cup goes to my mouth and i drink it. What i want is, that everytime i click a cup and drinks it, a variable called drunkness goes one up.
What ive done trying to achieve this is i call a function (depends on the player) at the yield waitforseconds (2) which is where you drink the cup, and in that function i get the variable from another script and adds one two it. But everytime i drink a cup, the counter goes up to 100 or something, and not only 1. Please help.