so i want to make it so that this snake (player) moves by the position of the mouse on the screen but when i put a number or even a number variable it gives me a error
Assets\playermovement.cs(13,13): error CS0019: Operator ‘>’ cannot be applied to operands of type ‘Vector3’ and ‘int’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playermovement : MonoBehaviour
{
public float f;
// Update is called once per frame
void FixedUpdate()
{
if (Input.mousePosition > ) { }
}
}
Doesn’t really make sense to do this kind of comparison. A Vector3 is a position in space with 3 components: x, y, z. There really isn’t a proper > for that. You’d want to instead compare to one of its components, so Input.mousePosition.x for instance.
void FixedUpdate()
{
/*
we need to translate mouse from screen position to world position
we cannot compare a Vector3 so lets look at .x
if script attached to player then transform is player
*/
if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > transform.position.x ) {//move right }
}