I want to move the plaftomer in pong game when u drag the mouse in the collider. But it isnt working. Can u help me?
2p01 is name of object with collider and Player Transform is the platform.
private var ray : Ray;
private var rayCastHit : RaycastHit;
var Player : Transform;
function Update ()
{
if(Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, rayCastHit))
{
if(rayCastHit.transform.name == "2p01")
{
Move ();
}
}
}
}
function Move()
{
Player.transform.position.x = ray.point.x;
}