Advertisement
Guest User

Why my functions can't talk to each other !! WTF

a guest
Feb 5th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.14 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7.  
  8.     private Animator m_animator;
  9.     private Rigidbody2D m_rigidbody2D;
  10.     private bool m_isMoving;
  11.     private Vector2 m_velocity;
  12.     private float m_curSpeed = 10.0f;
  13.     private float m_angle;
  14.     private int clicFunction2; //0 pas de fonction, 1 fonction selectionnée, 2 Click de souris pour envoyer la bullet
  15.     private bool m_boost;
  16.     private float m_durationBoost;
  17.     private Manager m_managerScript;
  18.  
  19.     public Texture2D m_cursorTexture;
  20.    
  21.     private Vector3 mousePos;
  22.  
  23.     private GameObject Button_Function_02;
  24.     public GameObject TitTat;
  25.     public GameObject MoleculeInstable;
  26.  
  27.     public float countdownFunction01;
  28.     public float countdownFunction02;
  29.     public float countdownFunction03;
  30.     public float countdownFunction04;
  31.     public float countdownFunction05;
  32.     public float countdownFunction06;
  33.  
  34.  
  35.     void Start ()
  36.     {
  37.         countdownFunction01 = 0;
  38.         countdownFunction02 = 0;
  39.         countdownFunction03 = 0;
  40.         countdownFunction04 = 0;
  41.         countdownFunction05 = 0;
  42.         countdownFunction06 = 0;
  43.  
  44.         Button_Function_02 = GameObject.Find("Button_Function_02");
  45.         m_animator = GetComponent<Animator>();
  46.         m_rigidbody2D = GetComponent<Rigidbody2D>();
  47.         m_isMoving = false;
  48.         m_velocity = new Vector2(0, 0);
  49.         clicFunction2 = 0;
  50.         m_boost = false;
  51.         m_managerScript = GameObject.Find("_manager").GetComponent<Manager>();
  52.         m_durationBoost = 5.0f;
  53.     }
  54.    
  55.     void Update ()
  56.     {
  57.        
  58.         if (countdownFunction01 >= 0)
  59.             countdownFunction01 -= Time.deltaTime;
  60.         if (countdownFunction02 >= 0)
  61.             countdownFunction02 -= Time.deltaTime;
  62.         if (countdownFunction03 >= 0)
  63.             countdownFunction03 -= Time.deltaTime;
  64.         if (countdownFunction04 >= 0)
  65.             countdownFunction04 -= Time.deltaTime;
  66.         if (countdownFunction05 >= 0)
  67.             countdownFunction05 -= Time.deltaTime;
  68.         if (countdownFunction06 >= 0)
  69.             countdownFunction06 -= Time.deltaTime;
  70.  
  71.  
  72.         if (clicFunction2 == 0)
  73.             Button_Function_02.GetComponent<Button>().image.color = Color.white;
  74.         if (clicFunction2 == 1)
  75.         {
  76.             Button_Function_02.GetComponent<Button>().image.color = Color.red;
  77.             Cursor.SetCursor(m_cursorTexture, Vector2.zero, CursorMode.Auto);
  78.         }
  79.         if (clicFunction2 == 2)
  80.         {
  81.             Instantiate(MoleculeInstable, transform.position, transform.rotation);
  82.             clicFunction2 = 0;
  83.             Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
  84.         }
  85.  
  86.         if (Input.GetMouseButtonDown(0))
  87.         {
  88.             if (clicFunction2 == 1)
  89.             {
  90.                 clicFunction2 = 2;
  91.                 countdownFunction02 = 6;
  92.             }  
  93.         }
  94.  
  95.         if (m_boost)
  96.             m_durationBoost -= Time.deltaTime;
  97.             m_curSpeed = 20.0f;
  98.         if (!m_boost)
  99.             m_curSpeed = 10.0f;
  100.         if (m_durationBoost <= 0)
  101.         {
  102.             m_boost = false;
  103.             m_durationBoost = 5.0f;
  104.         }
  105.  
  106.         m_velocity = new Vector2(0, 0);
  107.  
  108.         //INPUTS
  109.         if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Z)|| Input.GetKey(KeyCode.W))
  110.         {
  111.             Vector2 velUp = new Vector2();
  112.             velUp.y = 1;
  113.             m_velocity += velUp;
  114.         }
  115.         else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
  116.         {
  117.             Vector2 velDown = new Vector2();
  118.             velDown.y = -1;
  119.             m_velocity += velDown;
  120.         }
  121.  
  122.         if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.A))
  123.         {
  124.             Vector2 velLeft = new Vector2();
  125.             velLeft.x = -1;
  126.             m_velocity += velLeft;
  127.         }
  128.         else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
  129.         {
  130.             Vector2 velRight = new Vector2();
  131.             velRight.x = 1;
  132.             m_velocity += velRight;
  133.         }
  134.  
  135.         //Rotation of RigidBody2D
  136.         if (m_velocity.magnitude > 0.001)
  137.         {
  138.             m_velocity.Normalize();
  139.             m_velocity *= m_curSpeed;
  140.             m_rigidbody2D.velocity = m_velocity;
  141.             m_angle = Mathf.Atan2(m_rigidbody2D.velocity.y, m_rigidbody2D.velocity.x) * Mathf.Rad2Deg - 90;
  142.             transform.rotation = Quaternion.AngleAxis(m_angle, new Vector3(0, 0, 1));
  143.         }
  144.         else
  145.         {
  146.             m_rigidbody2D.velocity = new Vector2(0,0);
  147.         }
  148.  
  149.  
  150.         //Variables
  151.         if (m_rigidbody2D.velocity != new Vector2(0, 0))
  152.             m_isMoving = true;
  153.         else
  154.             m_isMoving = false;
  155.  
  156.         //Animations  
  157.         if (m_isMoving)
  158.             m_animator.SetBool("Moving", true);
  159.         else
  160.             m_animator.SetBool("Moving", false);
  161.    
  162.     }
  163.  
  164.  
  165.     public void Function01()
  166.     {
  167.         Debug.Log("in function01 : " + countdownFunction01);
  168.         if (countdownFunction01 <= 0)
  169.         {
  170.             Instantiate(TitTat, transform.position, transform.rotation);
  171.  
  172.             countdownFunction01 = 2;
  173.             Debug.Log("InsideThe if ! : " + countdownFunction01);
  174.         }
  175.        
  176.     }
  177.  
  178.     public void Function02()
  179.     {
  180.         if (countdownFunction02 <= 0)
  181.         {
  182.             Button_Function_02.GetComponent<Button>().image.color = Color.red;
  183.             clicFunction2 = 1;
  184.         }
  185.     }
  186.  
  187.     public void Function03()
  188.     {
  189.         if (countdownFunction03 <= 0)
  190.         {
  191.             m_boost = true;
  192.  
  193.             countdownFunction03 = 7;
  194.         }
  195.        
  196.     }
  197.  
  198.     public void Function04()
  199.     {
  200.         if (countdownFunction04 <= 0)
  201.         {
  202.  
  203.             countdownFunction04 = 10;
  204.         }
  205.     }
  206.  
  207.     public void Function05()
  208.     {
  209.         if (countdownFunction05 <= 0)
  210.         {
  211.  
  212.             countdownFunction05 = 15;
  213.         }
  214.     }
  215.  
  216.     public void Function06()
  217.     {
  218.         if (countdownFunction06 <= 0)
  219.         {
  220.  
  221.             countdownFunction06 = 22;
  222.         }
  223.     }
  224.  
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement