-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
44 lines (36 loc) · 1.18 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof (PlayerController))]
[RequireComponent (typeof (GunController))]
public class Player : LivingEntity {
public float moveSpeed = 5;
Camera viewCamera;
PlayerController controller;
GunController gunController;
protected override void Start () {
base.Start ();
controller = GetComponent<PlayerController> ();
gunController = GetComponent<GunController> ();
viewCamera = Camera.main;
}
void Update () {
// Movement input
Vector3 moveInput = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
Vector3 moveVelocity = moveInput.normalized * moveSpeed;
controller.Move (moveVelocity);
// Look input
Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
Plane groundPlane = new Plane (Vector3.up, Vector3.zero);
float rayDistance;
if (groundPlane.Raycast(ray,out rayDistance)) {
Vector3 point = ray.GetPoint(rayDistance);
//Debug.DrawLine(ray.origin,point,Color.red);
controller.LookAt(point);
}
// Weapon input
if (Input.GetMouseButton(0)) {
gunController.Shoot();
}
}
}