You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
2.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterMovement : MonoBehaviour {
public float Speed;
GameObject localPlayer;
public List<GameObject> Players = new List<GameObject>();
public List<bool> Nearby = new List<bool>();
public float DistanceToWin;
Camera cam;
private void Start()
{
localPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer;
Players.Add(localPlayer);
foreach (GameObject curPlayer in Multiplayer.PlayersManager.Instance.RemotePlayers.Values)
{
Players.Add(curPlayer);
}
cam = localPlayer.GetComponentInChildren<Camera>();
}
//Public movement functions :)
public void MoveLeft()
{
localPlayer.GetComponent<Rigidbody>().AddForce(new Vector3(-Speed, 0.0f, 0.0f));
}
public void MoveRight()
{
localPlayer.GetComponent<Rigidbody>().AddForce(new Vector3(Speed, 0.0f, 0.0f));
}
public void MoveUp()
{
localPlayer.GetComponent<Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, Speed));
}
public void MoveDown()
{
localPlayer.GetComponent<Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, -Speed));
}
public void mouseClick()
{
Vector3 screenMouse = Input.mousePosition;
Vector3 mousePos = cam.ScreenToWorldPoint(screenMouse);
Vector3 moveVec = new Vector3(mousePos.x, 0.0f, mousePos.z) * Speed;
localPlayer.GetComponent<Rigidbody>().AddForce(moveVec);
}
public bool CheckNearby()
{
for (int i = 0; i < Players.Count; i++)
{
if ((localPlayer.transform.position - Players[i].transform.position).magnitude < DistanceToWin)
{
Greet();
}
else
{
Player playerScript = Players[i].GetComponent<Player>();
foreach (GameObject dummy in playerScript.dummies)
{
if ((localPlayer.transform.position - dummy.transform.position).magnitude < DistanceToWin)
{
Greet();
}
}
}
}
return CheckWin();
}
bool CheckWin()
{
for (int i = 0; i < Nearby.Count; i++)
{
if (Nearby[i] == false)
{
return false;
}
}
return true;
}
public void Greet()
{
//Play audio
//Trigger animation
}
}