2019-08-03 22:21:47 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2019-08-04 00:59:18 +02:00
|
|
|
|
private Gun Gun;
|
|
|
|
|
|
|
|
|
|
private Vector2 GunLocation = new Vector2(0.1f, -0.7f);
|
|
|
|
|
private Vector3 GunRotation = new Vector3(0, 0, -90);
|
|
|
|
|
|
2019-08-03 22:21:47 +02:00
|
|
|
|
void Start() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
|
float X = Input.GetAxis("Horizontal");
|
|
|
|
|
float Y = Input.GetAxis("Vertical");
|
|
|
|
|
|
|
|
|
|
Vector2 Direction = new Vector2(X, Y).normalized;
|
|
|
|
|
|
2019-08-04 00:59:18 +02:00
|
|
|
|
Body.velocity = Direction * MoveSpeed;
|
2019-08-03 22:21:47 +02:00
|
|
|
|
|
|
|
|
|
Vector3 MousePos = Input.mousePosition;
|
|
|
|
|
Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos);
|
|
|
|
|
|
2019-08-04 00:59:18 +02:00
|
|
|
|
Vector2 LookDirection = (PointedPos - Hand.position).normalized;
|
2019-08-03 22:21:47 +02:00
|
|
|
|
|
|
|
|
|
var Rot = Hand.localEulerAngles;
|
|
|
|
|
Rot.z = Mathf.Atan2(LookDirection.y, LookDirection.x) * Mathf.Rad2Deg + 90;
|
|
|
|
|
Hand.localEulerAngles = Rot;
|
|
|
|
|
|
|
|
|
|
bool Shoot = Input.GetButtonDown("Shoot");
|
2019-08-04 00:59:18 +02:00
|
|
|
|
if (Shoot && Gun != null) {
|
|
|
|
|
Gun.Shoot(Gun.transform.position, LookDirection, Rot.z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetGun(Gun gun) {
|
|
|
|
|
if (Gun != null) {
|
|
|
|
|
Destroy(Gun.gameObject);
|
2019-08-03 22:21:47 +02:00
|
|
|
|
}
|
2019-08-04 00:59:18 +02:00
|
|
|
|
Gun = gun;
|
|
|
|
|
Gun.transform.parent = Hand;
|
|
|
|
|
Gun.transform.localPosition = GunLocation;
|
|
|
|
|
Gun.transform.localEulerAngles = GunRotation;
|
2019-08-03 22:21:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|