Reputation: 11
I am not able to convert from 'UnityEngine.Touch' to 'float' in line no.18 Please help?
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * movementSpeed;
public class RacketPlayer1 : MonoBehaviour {
public float movementSpeed;
private void FixedUpdate(){
if(Input.touchCount>0)
{
UnityEngine.Touch v = Input.touches[0];
if(v.phase == TouchPhase.Stationary || v.phase == TouchPhase.Moved )
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * movementSpeed;
}
}
}
}
Upvotes: 0
Views: 90
Reputation: 2417
Because vector2 => (float x,float y) , I guess you want to set position so
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * movementSpeed;
change to :
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v.position.y) * movementSpeed;
https://docs.unity3d.com/ScriptReference/Touch-position.html
Upvotes: 2