Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SlimeController : MonoBehaviour {
- //variable of how quick the player should move
- public float moveSpeed;
- //give the slime physics/a physical body
- private Rigidbody2D slimeRigidbody;
- //variable to check if the slime is moving
- private bool isMoving;
- //variable for the time of the different idles
- public float timeBetweenMove;
- //variable for the countdown of the different idles
- private float timeBetweenMoveCounter;
- //variable for the time of the different moves
- public float timeToMove;
- //variable for the countdown of the different moves
- private float timeToMoveCounter;
- //a variable for the direction the slime is moving
- private Vector3 moveDirection;
- /*int player_ID = GlobalPlayerController.Instance.player_ID;*/
- int player_ID;
- //is called before initialization
- void Start () {
- player_ID = FindObjectOfType<GlobalPlayerController>().player_ID;
- //give the slime a Rigidbody2Ds
- slimeRigidbody = GetComponent<Rigidbody2D>();
- /*timeBetweenMoveCounter = Random.Range(timeBetweenMove * 0.75f, timeBetweenMove * 1.25f);
- timeToMoveCounter = Random.Range(timeToMove * 0.75f, timeToMove * 1.25f);*/
- timeBetweenMoveCounter = Random.Range(0, 5);
- timeToMoveCounter = Random.Range(0, 3);
- }
- void Update () {
- if (isMoving)
- {
- timeToMoveCounter -= Time.deltaTime;
- slimeRigidbody.velocity = moveDirection;
- if(timeToMoveCounter < 0f)
- {
- isMoving = false;
- //timeBetweenMoveCounter = Random.Range(timeBetweenMove * 0.75f, timeBetweenMove * 1.25f);
- timeBetweenMoveCounter = Random.Range(0, 5);
- }
- }
- else
- {
- timeBetweenMoveCounter -= Time.deltaTime;
- slimeRigidbody.velocity = Vector2.zero;
- if(timeBetweenMoveCounter < 0f)
- {
- isMoving = true;
- //timeToMoveCounter = Random.Range(timeToMove * 0.75f, timeToMove * 1.25f);
- timeToMoveCounter = Random.Range(0, 3);
- moveDirection = new Vector3(Random.Range(-1f, 1f) * moveSpeed, Random.Range(-1f, 1f) * moveSpeed, 0f);
- }
- }
- }
- void OnCollisionEnter2D(Collision2D collision)
- {
- if(collision.gameObject.name == "Player_1" || collision.gameObject.name == "Player_2" || collision.gameObject.name == "Player_3")
- {
- if (GlobalPlayerController.Instance.players.Count == 3 && collision.gameObject.name == "Player_1")
- {
- /*collision.gameObject.GetComponent<GlobalPlayerController>().players.Remove(collision.gameObject);*/
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_1 has been removed");
- GameObject.Find("Player_2").GetComponent<PlayerController>().characterID = 0;
- GameObject.Find("Player_3").GetComponent<PlayerController>().characterID = 1;
- /*Global.i.*/
- player_ID++;
- /*if (player_ID == /*GlobalPlayerController.Instance.players.Count -1 FindObjectOfType<GlobalPlayerController>().players.Count )
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }*/
- }
- if (GlobalPlayerController.Instance.players.Count == 3 && collision.gameObject.name == "Player_2")
- {
- /*collision.gameObject.GetComponent<GlobalPlayerController>().players.Remove(collision.gameObject);*/
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- GameObject.Find("Player_1").GetComponent<PlayerController>().characterID = 0;
- GameObject.Find("Player_3").GetComponent<PlayerController>().characterID = 1;
- if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }
- }
- if (GlobalPlayerController.Instance.players.Count == 3 && collision.gameObject.name == "Player_3")
- {
- /*collision.gameObject.GetComponent<GlobalPlayerController>().players.Remove(collision.gameObject);*/
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- GameObject.Find("Player_1").GetComponent<PlayerController>().characterID = 0;
- GameObject.Find("Player_2").GetComponent<PlayerController>().characterID = 1;
- if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }
- }
- if ((GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_2" && GameObject.Find("Player_2") && GameObject.Find("Player_3")) || (GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_3" && GameObject.Find("Player_2") && GameObject.Find("Player_3")))
- {
- if (collision.gameObject.name == "Player_2")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_2 has been removed");
- GameObject.Find("Player_3").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }
- }
- if (collision.gameObject.name == "Player_3")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_3 has been removed");
- GameObject.Find("Player_2").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }
- }
- }
- if((GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_1" && GameObject.Find("Player_3") && GameObject.Find("Player_1")) || (GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_3" && GameObject.Find("Player_3") && GameObject.Find("Player_1")))
- {
- if (collision.gameObject.name == "Player_1")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_1 has been removed");
- GameObject.Find("Player_3").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- /*if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }*/
- }
- if (collision.gameObject.name == "Player_3")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_3 has been removed");
- GameObject.Find("Player_1").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- /*if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }*/
- }
- }
- if ((GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_1" && GameObject.Find("Player_2") && GameObject.Find("Player_1")) || (GlobalPlayerController.Instance.players.Count == 2 && collision.gameObject.name == "Player_2" && GameObject.Find("Player_2") && GameObject.Find("Player_1")))
- {
- if (collision.gameObject.name == "Player_1")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_1 has been removed");
- GameObject.Find("Player_2").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- /*if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }*/
- }
- if (collision.gameObject.name == "Player_2")
- {
- GlobalPlayerController.Instance.players.Remove(collision.gameObject);
- Debug.Log(GlobalPlayerController.Instance.players.Remove(collision.gameObject));
- Debug.LogFormat("Player_2 has been removed");
- GameObject.Find("Player_1").GetComponent<PlayerController>().characterID = 0;
- player_ID++;
- /*if (player_ID == GlobalPlayerController.Instance.players.Count -1)
- {
- player_ID = 0;
- Debug.LogFormat("ID has been reset/set to 0");
- }
- else
- {
- player_ID++;
- Debug.LogFormat("ID has been changed");
- }*/
- }
- }
- collision.gameObject.SetActive(false);
- GameObject.Find("Scripts").GetComponent<GlobalPlayerController>().player_ID++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement