Hi,
I am trying to get a cube to display some text if the player rightclicks on it and is close enough to it. If the player is not close enough, he will automatically walk towards it and display the text as soon as he is close enough. If the player chooses to walk somewhere else instead, the function should stop.
I thought I would have a a bool that gets set to false when the player clicks on the cube and gets set to true if he clicks somewhere else and the message would only display when that bool is set to false.
So far so good. However, everytime I click on the cube, it sets the bool to false and then immediatly to true again.
So my question would be if I can somehow determine in which order those commands are being executed?
Also, I am completely new to this (literally started yesterday), so if there is a much better way to achieve this, please enlighten me ![]()
Here`s the code I have so far (the walking is handled in a different script that is working fine):
#pragma strict
var CubeObject :GameObject;
var Player :GameObject;
private var distance :float;
private var RMBclicked :boolean;
function OnMouseOver()
{
if (Input.GetMouseButtonDown(1))
{
RMBclicked = false;
print ("false");
}
}
function Update ()
{
distance = Vector3.Distance(CubeObject.transform.position, Player.transform.position);
if (Input.GetMouseButtonDown (1))
{
RMBclicked = true;
print ("true");
}
if (distance <3)
{
if (RMBclicked == false)
{
print ("Hello");
//RMBclicked = true;
//print ("true Dist");
}
}
}
function LateUpdate ()
{
}