Exemple #1
0
    /*
     * Main game loop function. This function is called for every monobehaviour every frame
     * We use it to run the functions that happen constantly like cone of vision
     * and checking if we're in base
     *
     */
    void Update()
    {
        if (!Gunshot.isPlaying)
        {
            Gunshot.enabled = false;
        }

        checkZone();
        if (MyTeam == team.blue)
        {
            if (myZone == zone.BlueBase)
            {
                loadoutFlag = true;
            }
            else
            {
                loadoutFlag = false;
            }
        }
        if (MyTeam == team.red)
        {
            if (myZone == zone.RedBase)
            {
                loadoutFlag = true;
            }
            else
            {
                loadoutFlag = false;
            }
        }
        if (health > 0)
        {
            if (!turnLock)
            {
                TurnChar();
            }
            visible.Clear();
            visibleEnemyLocations.Clear();
            GetVisibleObjects(visible);
            Fire(priority);
            AnimDoneMoving(1.0f);
        }
        else if (currentState != characterState.RESPAWNING)
        {
            currentState = characterState.RESPAWNING;
            refreshRespawnTimer();
            IDied.Invoke();
            prefabObject.SetActive(false);
        }
        else if (respawnTImer == 0)
        {
            currentState    = characterState.ALIVE;
            moveDestination = transform.position;
            health          = 100;
            prefabObject.transform.position = transform.position;
            IGotHit.Invoke(MyTeam, playerNumber, health);
            prefabObject.SetActive(true);
        }
    }
    public void ChangeX(float offset)
    {
        Debug.Log("ChangeX : " + offset);
        this.x += offset;
        Vector2 v2 = this.transform.ToRectTransform().anchoredPosition;

        this.transform.ToRectTransform().anchoredPosition = new Vector2(v2.x + offset, v2.y);
        myEvent.Invoke(new Vector3(x, y, z));
    }
Exemple #3
0
    private void ChekPosition()
    {
        var position = new Vector2(transform.position.x, transform.position.y);

        if (_spotsPositions != null)
        {
            for (int i = 0; i < _spotsPositions.Count; i++)
            {
                if (_selectedSpot == null && _spotsPositions[i].activeSelf)
                {
                    if (Vector2.Distance(position, _spotsPositions[i].transform.position) < _distance)
                    {
                        _selectedSpot = _spotsPositions[i];
                        therapy.Invoke(_spotsPositions[i].name);
                    }
                }
                else
                {
                    if (_selectedSpot == _spotsPositions[i])
                    {
                        if (Vector2.Distance(position, _spotsPositions[i].transform.position) < _distance)
                        {
                            if (_sliderValue <= 100)
                            {
                                _slider.gameObject.SetActive(true);
                                _slider.SliderChange(_sliderValue, 100f);
                                _sliderValue += Time.deltaTime * _sliderSpeed;
                            }
                            else
                            {
                                if (!SuccessfulDeseaseChek(_spotsPositions[i]))
                                {
                                    _spotsPositions[i].SetActive(false);
                                    _sliderValue = 0;
                                    _spotsPositions.Remove(_spotsPositions[i]);
                                    _slider.gameObject.SetActive(false);
                                    _selectedSpot = null;
                                }
                            }
                        }
                        else
                        {
                            _selectedSpot = null;
                            _slider.gameObject.SetActive(false);
                            _sliderValue = 0;
                            therapy.Invoke("Cancel");
                        }
                    }
                }
            }
        }
    }
Exemple #4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         OnClicked.Invoke(a);
     }
 }
Exemple #5
0
        public event DelegateForEvent MyEvent; //My event

        public void EventInvoker()
        {
            if (MyEvent != null)
            {
                MyEvent.Invoke();                  //Invoking my event
            }
        }
Exemple #6
0
 public void RaiseEvent()
 {
     if (MyEvent != null)
     {
         MyEvent.Invoke(this, EventArgs.Empty);
     }
 }
 private void CustomButton_MouseClick(object sender, MouseEventArgs e)
 {
     if (MyEvent != null)
     {
         MyEvent.Invoke(sender, e);
     }
 }
Exemple #8
0
 public event EventDelegate MyEvent = null; //Мы создаем открытое событие с именем MyEvent типа EventDelegate
 //1-я особенность слова event - В object Browser`e поигрался с удалением слова event и увидел как молния прверащается в обычное поле
 //2-Я особенность слова event - запрещено на событии извне вызывать метод Invoke
 //ГЛАВНОЕ ЗАПОМНИТЬ: если поле является событием, то это поле ТИПА КАКОГО-ТО ДЕЛЕГАТА
 public void InvokeEvent()
 {//зачем вообще делать обертку на вызов события?
     //в этом методе можно делать какие-угодно проверки и исходя из их результата либо вызывать событие - либо нет.
     //например - если меня толкает Александр - то вызывать, а если нет - то делать что-то другое(например бежать)
     //if(alexandr)
     MyEvent.Invoke();
 }
Exemple #9
0
 public void ExecMoveEffect(int ret)
 {
     if (MoveEffect != null)
     {
         MoveEffect.Invoke(0);
     }
 }
    void OnTriggerEnter2D(Collider2D player)
    {
        if (player.tag == "Player" && !this.activated)
        {
            activatedButtons++;
            this.activated        = true;
            render.material.color = Color.green;
            switch (activatedButtons)
            {
            case 1:
                Player.INSTANCE.Talk("Hey the button changed color.\nIt probably did something");
                break;

            case 2:
                Player.INSTANCE.Talk("I think I heard something,\nmaybe something happened ?");
                //ouvre la porte secrete
                secretDoor.Invoke();
                break;

            case 3:
                Player.INSTANCE.Talk("Quickly ! I need to get to the other side !");
                timerMiniGame.Invoke();
                StartCoroutine(TimeOutDoor());
                //lance un timer dans l'UI de 15 secondes
                GetComponent <Timer> ().StartTimer(15);
                break;
            }
        }
    }
    //pulls the "trigger" (will not fire without a round in the chamber and a mag in)
    public void Fire()
    {
        if (ChamberedCheck())
        {
            //fire
            //raycast
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, RayCastLength))
            {
                if (hit.collider.tag == "Animal")
                {
                    //deal damage to whatever we hit
                    hit.collider.GetComponent <Health>().TakeDamage(RayCastDamage);
                }
            }

            //fire
            InMag--;
            ReadyToFireTime = -1 / (FireRPM / 60);
            OnFire.Invoke();
            if (InMag <= 0)
            {
                OnEmptyMag.Invoke();
            }
        }
        else if (Reloading == false && InMag <= 0)
        {
            OnDryFire.Invoke();
        }
    }
Exemple #12
0
 public void InvokeEvent()
 {
     if (MyEvent != null)
     {
         MyEvent.Invoke();
     }
 }
Exemple #13
0
    IEnumerator ActionHummer()
    {
        isSubmit = true;
        if (isSelectHummer && selectImage != null)
        {
            var angle = selectImage.rotation;
            for (int i = 0; i < 4; i++)
            {
                var r = selectImage.localEulerAngles;
                r.z -= 70.0f / 4;
                selectImage.localEulerAngles = r;
                yield return(null);
            }
            StartCoroutine(ActionWaitUp(angle));
        }
        else
        {
            StartCoroutine(WaitUp());
        }
        transform.GetChild(selectIndex).localScale -= selectScale;

        transform.GetChild(selectIndex).GetComponent <Image>().color = unselectColor;

        UnityEngine.EventSystems.BaseEventData data = new UnityEngine.EventSystems.BaseEventData(UnityEngine.EventSystems.EventSystem.current);
        transform.GetChild(selectIndex).GetComponent <Button>().OnSubmit(data);
        action.Invoke(transform.GetChild(selectIndex).gameObject);
    }
Exemple #14
0
 public void CheckClick(int x, int y)
 {
     if (destination.Contains(x, y))
     {
         onClick.Invoke(this); //actions on button click
     }
 }
Exemple #15
0
    private void Start()
    {
        //We set enums with the set values
        myGameState = GameState.PreGame;
        //We can ask for (and assign from) the number our enum corresponds to
        Debug.Log((int)myGameState);
        //Be wary of doing this, it won't know what to do if we go myGameState = (GameState)4 for example

        //We're using the constructor so we're instantiating the struct with initial values
        MyDataPack data = new MyDataPack(5, "test");

        if (myGameState == GameState.PostGame)
        {
            numbersAsWords = NumbersAsWords.X;
            Debug.Log(numbersAsWords);
        }

        //How we start our coroutine, we can also use a string, and we can stop them selectively or all at once
        StartCoroutine(MyCoroutine());

        //My animator is handling my states and transitions
        graphicalStateMachine.SetFloat("HealthPercent", 20);   //I keep the values in the animator updated, it handles behaviour

        //Adding to, and calling, our delegate and our event
        myDelegate += LookForHealth;

        MyEvent += LookForHealth;

        myDelegate.Invoke();

        MyEvent.Invoke();
    }
Exemple #16
0
 private void Notice()
 {
     if (Event != null)
     {
         Event.Invoke(data);
     }
 }
Exemple #17
0
 void Punch(Vector3 position)
 {
     if (invulnerable)
     {
         return;
     }
     if (guard)
     {
         stamina -= 10;
         whenLoseStamina.Invoke(stamina.ToString());
         return;
     }
     print("Auch...");
     if (!anim.GetCurrentAnimatorStateInfo(0).IsName("FALL_Player"))
     {
         invulnerable = true;
         StartCoroutine(SetVulnerable());
         anim.SetTrigger("getPunch");
         position.y = transform.position.y;
         rb.AddForce((transform.position - position) * force, ForceMode2D.Impulse);
         lives--;
         whenLoseLife.Invoke(lives.ToString());
         if (lives < 0)
         {
             whenDie.Invoke();
         }
     }
 }
 //reloads the gun and calls OnReloadComplete's events
 //NOTE USE RELOADSTART TO RELOAD AS Reload() will reload the gun instantly
 private void Reload()
 {
     ReadyToFireTime = 0;
     Reloading       = false;
     if (!InfiniteAmmoReserve)
     {
         //reload the ammo for non infinite guns
         if (AmmoReserve < MaxInMag)
         {
             InMag       = AmmoReserve;
             AmmoReserve = 0;
         }
         else
         {
             InMag        = MaxInMag;
             AmmoReserve -= MaxInMag;
         }
     }
     else
     {
         //reload ammo for infinite ammo gun
         InMag = MaxInMag;
     }
     OnReloadComplete.Invoke();
 }
 private void OnTriggerExit(Collider other)
 {
     if (other.CompareTag(targetTag))
     {
         Debug.Log(other.transform.name);
         OnTriggerExitEvent.Invoke();
     }
 }
 void OnMouseDown()
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     WhenMouseDown.Invoke();
 }
 //starts the reload process and calls OnReloadStart's events
 public void ReloadStart()
 {
     if (Reloading != true && AmmoReserve > 0)
     {
         OnReloadStart.Invoke();
         ReloadProgress = 0;
         Reloading      = true;
     }
 }
Exemple #22
0
        public static void TriggerEvent(string eventName, object eventData)
        {
            MyEvent thisEvent = null;

            if (Singleton.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.Invoke(eventData);
            }
        }
        /// <summary>
        /// Trigger specified event.
        /// </summary>
        /// <param name="eventName">Event name.</param>
        /// <param name="obj">Object.</param>
        /// <param name="param">Parameter.</param>
        public static void Trigger(string eventName, GameObject obj, object param)
        {
            MyEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.Invoke(obj, param);
            }
        }
Exemple #24
0
    // Start is called before the first frame update
    void Start()
    {
        fruit_script = GameObject.Find("Fruits");
        testEvt      = new MyEvent();
        testEvt.AddListener(test);

        //带参数的事件唤醒方式
        testEvt.Invoke(fruit_script, 2);
    }
 public void TakeDamage(int amount)
 {
     currentHealth -= amount;
     onHealthChange.Invoke((float)currentHealth / (float)maxHealth);
     if (currentHealth == 0)
     {
         GameMaster.KillPlayer(this);
     }
 }
Exemple #26
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //Debug.Log(collision.tag);
     if (collision.tag == "Player")
     {
         myEvent.Invoke(myStr, myGameObj);
         // can be used to send dynamic stuff like .SendMessage()
         // use myEvent.Invoke("ApplyDamage", gameObject) and config to .SendMessage()
         // to run .SendMessage("ApplyDamage", gameObject) when invoked.
         if (disableAfterCollision)
         {
             gameObject.SetActive(false);
         }
     }
     else
     {
         Debug.Log("Collided with non-player object!");
     }
 }
Exemple #27
0
 void CraftPoint()
 {
     print("CRAFTING...");
     buildTime--;
     if (buildTime <= 0)
     {
         onCraftCompleted.Invoke();
         craftUncompletedGO.SetActive(false);
         craftCompletedGO.SetActive(true);
     }
 }
 public void MyMethod(int myNumber)
 {
     Console.WriteLine(myNumber);
     if (myNumber == 7)
     {
         MyEvent.Invoke(null, new MyCustomEventArgs()
         {
             Foo = "Bar"
         });
     }
 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.J))
     {
         nextState = PlayerStates.attackReady;
         m_Event.Invoke(nextState);//Invoke the Event and notice the function which subscribe it and pass nextState to the function
     }
     else if (Input.GetKeyDown(KeyCode.K))
     {
         nextState = PlayerStates.walk;
         m_Event.Invoke(nextState);
     }
     else if (Input.GetKeyDown(KeyCode.L))
     {
         nextState = PlayerStates.idle;
         m_Event.Invoke(nextState);
     }
     else if (Input.GetKeyDown(KeyCode.I))
     {
         nextState = PlayerStates.sitDown;
         m_Event.Invoke(nextState);
     }
     else if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         nextState = PlayerStates.skill1;
         m_Event.Invoke(nextState);
     }
     else if (Input.GetKeyDown(KeyCode.Alpha2))
     {
         nextState = PlayerStates.skill2;
         m_Event.Invoke(nextState);
     }
 }
 void NotifyExplosionTriggered()
 {
     if (explosionTriggered != null)
     {
         explosionTriggered.Invoke();
     }
     else
     {
                     #if UNITY_EDITOR
         Debug.LogError("no \"explosionTriggered\" observer");
                     #endif
     }
 }