using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
public ControlType controlType;
public Joystick joystick;
public float speed;
public enum ControlType{PC, Android}
private Rigidbody2D rd;
private Vector2 moveInput;
private Vector2 moveVelocity;
void Start()
{
rd = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (controlType == ControlType.PC)
{
moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
else if(controlType == ControlType.Android)
{
moveInput = new Vector2(joystick.Horizontal, joystick.Vertical);
}
moveVelocity = moveInput.normalized * speed;
}
void FixedUpdate()
{
rd.MovePosition(rd.position + moveVelocity * Time.fixedDeltaTime);
}
}