Im using RaycastHit to detect if I’m looking at any objects, and if I am, I can teleport onto them.
However at the minute it teleports onto the middle of the object, but I want it to teleport to whereever on the object was clicked. How would I do that?
This is what I have so far.
var hit: RaycastHit;
if(Physics.Raycast(Gun.transform.position, Gun.transform.forward, hit)){
if(hit.transform.tag == 'JumpTo'){
Text.guiTexture.enabled = true;
if(Input.GetButtonDown("Fire1")){
var distance = Vector3.Distance(Player.transform.position,hit.transform.position);
if(distance < 17)
Player.transform.position = Vector3.Lerp(Player.transform.position,hit.transform.position+(Vector3.up*5), Time.time);
}
}
else
Text.guiTexture.enabled = false;
}