Hi. If the player clicks and their cursor is to the right of an object, I want to add force to move the object right. If the cursor is on the left, I want to add force to move it to the left. I cam up with this script, but I get these errors.
The best overload for the method
‘UnityEngine.Camera.ScreenPointToRay(UnityEngine.Vector3)’
is not compatible with the argument
list ‘(float)’.Operator ‘>=’ cannot be used with a
left hand side of type
‘UnityEngine.Ray’ and a right hand
side of type ‘float’.
function Update () {
if (Input.GetButtonDown ("Fire1")) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition.x);
if (ray >= gameObject.transform.position.x){
rigidbody.AddForce (Vector3.right * 5);
}
if (ray <= gameObject.transform.position.x){
rigidbody.AddForce (Vector3.right *-5);
}
}
}
What am I doing wrong? Thanks