- Home /
Getting MouseEnter to Another Object
Hello, I'm trying on my game again and I couldn't find any Documentation about this problem. As you can see the picture below I'm shooting the Duck.
When I shoot the duck, Counter should incrase and MissionBoard should decrase. They have their own code. The Counter's code is at below
#pragma strict
var counter : int;
var LeftDuck : GameObject;
var RightDuck : GameObject;
function Start () {
}
function Update () {
counter++;
var Text : TextMesh = gameObject.GetComponent(TextMesh);
Text.text = counter.ToString();
Debug.Log(counter);
}
I'm using Update Method Because of I don't know what to write :D I hope some one can help. I Want this exactly.
when i click to LeftDuck(Clone) or RightDuck(Clone) object, Increase variable "counter".
Please I only need this code and then my project finishes. Thanks a lot.
Answer by coolfireking2 · Aug 10, 2013 at 09:05 AM
Hello,
This may not be the best way to do it but this will work, Make a new script called something like DuckShoot in java script then write this in function update
if(Input.GetMouseButtonDown(0)){
NameOfScriptWithCounterOn.counter += 1;
NameOfScriptWithMissionBoardOn.MissionBoardVariable -= 1;
}
// 0 stands for left click, 1 for right and 2 for middle
Next you need to open your Counter code script and your mission board script and add static to your variables e.g.
static var counter = 0; or static var counter : int; static var missionBoard = 0; or static var missionBoard : int;
then you are done! The only downside with this is that if you have a reset or reastart button then you will need to set the counter var back to 0 and the mission board to what the next mission is.
Joseph
Hmm. $$anonymous$$, I'm using Perfabs so in-game objects are (Clone) :/ Does it affect Whole ducks or shoud i create a "Contoller Item" ?
with this script having your duck have (clone) after it doesn't matter. You do not need to create a controller item.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111906im_/https://answers.unity.com/themes/thub/images/avi.jpg)