What I’m doing with this script is scaling a cube along the y axis (increasing with left mouse button and decreasing with right mouse button) while the player is in close proximity of it (between 2 and .1 units). I want the player to be able to be on top of the cube as it’s being scaled. I have the script attached to the cube and the player controller attached to the player variable in the inspector.
It was working like I wanted all day today, but now it’s not. Now, the cube is being scaled even when the player isn’t near it. I tried starting a new project; it worked briefly and then stopped. Any suggestions as to why this is happening? I don’t believe I changed anything, but I’m a total noob, so I could’ve done something and didn’t realize it.
I’m not really looking for any fixes to my script, although any suggestions to make it more efficient would be greatly appreciated. I would just like to figure out where I’m going wrong since, like I said, I had it working earlier.
var player : Transform;
function OnMouseOver ()
{
if(Input.GetButton("Fire1") && (Vector3.Distance(transform.position, player.position) < 2))
{
transform.localScale += new Vector3(0F, .1F, 0);
}
if(Input.GetButton("Fire1") && (Vector3.Distance(transform.position, player.position) > .1))
{
transform.localScale += new Vector3(0F, .1F, 0);
}
if(Input.GetButton("Fire2") && transform.localScale.y > 1f && (Vector3.Distance(transform.position, player.position) < 2))
{
transform.localScale += new Vector3(0F, -.1F, 0);
}
if(Input.GetButton("Fire2") && transform.localScale.y > 1f && (Vector3.Distance(transform.position, player.position) > .1))
{
transform.localScale += new Vector3(0F, -.1F, 0);
}
}
nope, it does not =(
– ChazAshley1