- Home /
OnMouseEnter Error
Hi, In a level I am currently making I need the player to teleport once they look at an object. I have this script currently. (in Javascript)
pragma strict
function Start () {
}
function Update () {
}
var destination : Transform;
function OnMouseEnter (other : Collider)
{
if (other.tag == "Player") {
other.transform.position = destination.position;
}
}
However, once I run the script after attaching it to the object and putting my mouse on it, I get the following error: Failed to call function OnMouseEnter of class HoverBotTeleportPlayer Calling function OnMouseEnter with no parameters but the function requires 1. UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
If anyone could explain why this happens and tell me how to fix it I would be extremely grateful.
Thanks, drjordanmathew
Answer by drjordanmathew · Mar 09, 2013 at 08:45 PM
Thank you. Basically I want the player (first person) to be teleported somewhere once he clicks on ANOTHER object. So if I move my mouse on a chair, I get teleported to my bathroom.
Does your code work with that concept?
The concept is pretty similar, you have to add the script to the object that will be checking if it has been clicked (in this case the chair). The script stays pretty much the same:
var player : Transform;
function On$$anonymous$$ouseEnter ()
{
player.transform.position = transform.position;
}
You have to assign the player game object to the player variable in the inspector ofcourse..
This script will detect if you clicked on the chair and then move the player to the chairs position. Let me know if you need more help :)
Thank You! I will try it out later but thanks for your help!
Your answer
Follow this Question
Related Questions
First time open error android game 0 Answers
SCRIPT NOT WORKING 2 Answers
Need Help Understanding Script! (Javascript) 1 Answer
Animation script error 1 Answer
Console Error 1 Answer