- Players can now die (finally) - Solo players have a single cheat death per scene (reviving automatically after the first death) - group players have revive mechanic, where a player faints when his health gets to 0, creating a revive circle around him, other players can stand on it to revive him. if after x seconds they don't get revived they bleed out and stay perma death until scene changes or all players die - Multiple VFX added using post processing for cheat death, fainting, reviving, and perma death events. - stopped players from moving and pressing keys when dead - enemies now change target if they try to attack a dead/fainted target.
151 lines
3.8 KiB
C#
151 lines
3.8 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
[RequireComponent(typeof(PlayerMovement))]
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
[Header("Listeners:")]
|
|
[SerializeField] private GameEventListener onLocalPlayerFainted;
|
|
[SerializeField] private GameEventListener onLocalPlayerPermaDeath;
|
|
[SerializeField] private GameEventListener onLocalPlayerRevived;
|
|
[Space]
|
|
|
|
public ParticleSystem clickArrows;
|
|
public Interactable focus;
|
|
|
|
public LayerMask movementMask;
|
|
public LayerMask interactableMask;
|
|
|
|
Camera cam;
|
|
public PlayerMovement motor;
|
|
|
|
Plane plane = new Plane(Vector3.down, 0);
|
|
|
|
PhotonView photonView;
|
|
|
|
Ray ray;
|
|
RaycastHit hit;
|
|
|
|
bool isDead;
|
|
|
|
private void Awake()
|
|
{
|
|
cam = Camera.main;
|
|
motor = GetComponent<PlayerMovement>();
|
|
photonView = GetComponent<PhotonView>();
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (!photonView.IsMine) this.enabled = false;
|
|
|
|
onLocalPlayerFainted.Response.AddListener(() =>
|
|
{
|
|
isDead = true;
|
|
motor.MoveToPoint(this.transform.position);
|
|
motor.ToggleAgentMoving(true);
|
|
});
|
|
onLocalPlayerPermaDeath.Response.AddListener(() =>
|
|
{
|
|
isDead = true;
|
|
motor.MoveToPoint(this.transform.position);
|
|
motor.ToggleAgentMoving(true);
|
|
});
|
|
onLocalPlayerRevived.Response.AddListener(() =>
|
|
{
|
|
isDead = false;
|
|
motor.ToggleAgentMoving(false);
|
|
});
|
|
|
|
clickArrows.transform.SetParent(null);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (isDead) return;
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
ray = cam.ScreenPointToRay(Input.mousePosition);
|
|
|
|
if (Physics.Raycast(ray, out hit, 100f, movementMask))
|
|
{
|
|
clickArrows.transform.position = hit.point;
|
|
clickArrows.Play();
|
|
}
|
|
}
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
ray = cam.ScreenPointToRay(Input.mousePosition);
|
|
|
|
if (Physics.Raycast(ray, out hit, 100f, movementMask))
|
|
{
|
|
motor.MoveToPoint(hit.point);
|
|
|
|
//Debug.Log("hitpoint: " + hit.point);
|
|
RemoveFocus();
|
|
}
|
|
else
|
|
{
|
|
if (plane.Raycast(ray, out float distance))
|
|
{
|
|
motor.MoveToPoint(ray.GetPoint(distance));
|
|
//Debug.Log("hitpoint: " + ray.GetPoint(distance));
|
|
RemoveFocus();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Input.GetMouseButton(1))
|
|
{
|
|
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
|
|
if (Physics.Raycast(ray, out hit, 100f, interactableMask))
|
|
{
|
|
Interactable interactable = hit.collider.GetComponent<Interactable>();
|
|
if (interactable != null)
|
|
{
|
|
SetFocus(interactable);
|
|
}
|
|
// if we did, set as focus
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetFocus(Interactable newFocus)
|
|
{
|
|
if (newFocus != focus)
|
|
{
|
|
if (focus != null)
|
|
{
|
|
focus.OnDeFocus();
|
|
}
|
|
focus = newFocus;
|
|
motor.FollowTarget(focus);
|
|
}
|
|
|
|
newFocus.OnFocused(transform, this);
|
|
}
|
|
|
|
public void RemoveFocus()
|
|
{
|
|
if (focus != null)
|
|
{
|
|
focus.OnDeFocus();
|
|
}
|
|
motor.StopFollowingTarget();
|
|
focus = null;
|
|
}
|
|
}
|