Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class Player : MonoBehaviour
- {
- private Animator m_animator;
- private Rigidbody2D m_rigidbody2D;
- private bool m_isMoving;
- private Vector2 m_velocity;
- private float m_curSpeed = 10.0f;
- private float m_angle;
- private int clicFunction2; //0 pas de fonction, 1 fonction selectionnée, 2 Click de souris pour envoyer la bullet
- private bool m_boost;
- private float m_durationBoost;
- private Manager m_managerScript;
- public Texture2D m_cursorTexture;
- private Vector3 mousePos;
- private GameObject Button_Function_02;
- public GameObject TitTat;
- public GameObject MoleculeInstable;
- public float countdownFunction01;
- public float countdownFunction02;
- public float countdownFunction03;
- public float countdownFunction04;
- public float countdownFunction05;
- public float countdownFunction06;
- void Start ()
- {
- countdownFunction01 = 0;
- countdownFunction02 = 0;
- countdownFunction03 = 0;
- countdownFunction04 = 0;
- countdownFunction05 = 0;
- countdownFunction06 = 0;
- Button_Function_02 = GameObject.Find("Button_Function_02");
- m_animator = GetComponent<Animator>();
- m_rigidbody2D = GetComponent<Rigidbody2D>();
- m_isMoving = false;
- m_velocity = new Vector2(0, 0);
- clicFunction2 = 0;
- m_boost = false;
- m_managerScript = GameObject.Find("_manager").GetComponent<Manager>();
- m_durationBoost = 5.0f;
- }
- void Update ()
- {
- if (countdownFunction01 >= 0)
- countdownFunction01 -= Time.deltaTime;
- if (countdownFunction02 >= 0)
- countdownFunction02 -= Time.deltaTime;
- if (countdownFunction03 >= 0)
- countdownFunction03 -= Time.deltaTime;
- if (countdownFunction04 >= 0)
- countdownFunction04 -= Time.deltaTime;
- if (countdownFunction05 >= 0)
- countdownFunction05 -= Time.deltaTime;
- if (countdownFunction06 >= 0)
- countdownFunction06 -= Time.deltaTime;
- if (clicFunction2 == 0)
- Button_Function_02.GetComponent<Button>().image.color = Color.white;
- if (clicFunction2 == 1)
- {
- Button_Function_02.GetComponent<Button>().image.color = Color.red;
- Cursor.SetCursor(m_cursorTexture, Vector2.zero, CursorMode.Auto);
- }
- if (clicFunction2 == 2)
- {
- Instantiate(MoleculeInstable, transform.position, transform.rotation);
- clicFunction2 = 0;
- Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
- }
- if (Input.GetMouseButtonDown(0))
- {
- if (clicFunction2 == 1)
- {
- clicFunction2 = 2;
- countdownFunction02 = 6;
- }
- }
- if (m_boost)
- m_durationBoost -= Time.deltaTime;
- m_curSpeed = 20.0f;
- if (!m_boost)
- m_curSpeed = 10.0f;
- if (m_durationBoost <= 0)
- {
- m_boost = false;
- m_durationBoost = 5.0f;
- }
- m_velocity = new Vector2(0, 0);
- //INPUTS
- if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Z)|| Input.GetKey(KeyCode.W))
- {
- Vector2 velUp = new Vector2();
- velUp.y = 1;
- m_velocity += velUp;
- }
- else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
- {
- Vector2 velDown = new Vector2();
- velDown.y = -1;
- m_velocity += velDown;
- }
- if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A))
- {
- Vector2 velLeft = new Vector2();
- velLeft.x = -1;
- m_velocity += velLeft;
- }
- else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
- {
- Vector2 velRight = new Vector2();
- velRight.x = 1;
- m_velocity += velRight;
- }
- //Rotation of RigidBody2D
- if (m_velocity.magnitude > 0.001)
- {
- m_velocity.Normalize();
- m_velocity *= m_curSpeed;
- m_rigidbody2D.velocity = m_velocity;
- m_angle = Mathf.Atan2(m_rigidbody2D.velocity.y, m_rigidbody2D.velocity.x) * Mathf.Rad2Deg - 90;
- transform.rotation = Quaternion.AngleAxis(m_angle, new Vector3(0, 0, 1));
- }
- else
- {
- m_rigidbody2D.velocity = new Vector2(0,0);
- }
- //Variables
- if (m_rigidbody2D.velocity != new Vector2(0, 0))
- m_isMoving = true;
- else
- m_isMoving = false;
- //Animations
- if (m_isMoving)
- m_animator.SetBool("Moving", true);
- else
- m_animator.SetBool("Moving", false);
- }
- public void Function01()
- {
- Debug.Log("in function01 : " + countdownFunction01);
- if (countdownFunction01 <= 0)
- {
- Instantiate(TitTat, transform.position, transform.rotation);
- countdownFunction01 = 2;
- Debug.Log("InsideThe if ! : " + countdownFunction01);
- }
- }
- public void Function02()
- {
- if (countdownFunction02 <= 0)
- {
- Button_Function_02.GetComponent<Button>().image.color = Color.red;
- clicFunction2 = 1;
- }
- }
- public void Function03()
- {
- if (countdownFunction03 <= 0)
- {
- m_boost = true;
- countdownFunction03 = 7;
- }
- }
- public void Function04()
- {
- if (countdownFunction04 <= 0)
- {
- countdownFunction04 = 10;
- }
- }
- public void Function05()
- {
- if (countdownFunction05 <= 0)
- {
- countdownFunction05 = 15;
- }
- }
- public void Function06()
- {
- if (countdownFunction06 <= 0)
- {
- countdownFunction06 = 22;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement