40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Saltosion.OneWeapon {
|
|||
|
public class Player : MonoBehaviour {
|
|||
|
|
|||
|
public Rigidbody2D Body;
|
|||
|
public Transform Hand;
|
|||
|
public float MoveSpeed = 50f;
|
|||
|
|
|||
|
void Start() {
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void Update() {
|
|||
|
float X = Input.GetAxis("Horizontal");
|
|||
|
float Y = Input.GetAxis("Vertical");
|
|||
|
|
|||
|
Vector2 Direction = new Vector2(X, Y).normalized;
|
|||
|
|
|||
|
Body.velocity = Direction * MoveSpeed * Time.deltaTime;
|
|||
|
|
|||
|
Vector3 MousePos = Input.mousePosition;
|
|||
|
Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos);
|
|||
|
|
|||
|
Vector2 LookDirection = PointedPos - Hand.position;
|
|||
|
|
|||
|
var Rot = Hand.localEulerAngles;
|
|||
|
Rot.z = Mathf.Atan2(LookDirection.y, LookDirection.x) * Mathf.Rad2Deg + 90;
|
|||
|
Hand.localEulerAngles = Rot;
|
|||
|
|
|||
|
bool Shoot = Input.GetButtonDown("Shoot");
|
|||
|
if (Shoot) {
|
|||
|
Debug.Log(LookDirection.normalized);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|