Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (running && remainingTime > 0)
        {
            timeText.text = remainingTime.ToString("0.00");

            remainingTime -= Time.deltaTime;
        }
        if (remainingTime <= 0)
        {
            HealthHandler p1Health = GameObject.FindGameObjectWithTag("Player 1").GetComponent <HealthHandler> ();
            HealthHandler p2Health = GameObject.FindGameObjectWithTag("Player 2").GetComponent <HealthHandler> ();
            fightUI.enabled    = false;
            gameOverUI.enabled = true;

            if (p1Health.curHP > p2Health.curHP)
            {
                gameOverText.text = "Player 1 Wins!";
            }
            else if (p1Health.curHP < p2Health.curHP)
            {
                gameOverText.text = "Player 2 Wins!";
            }
            else
            {
                gameOverText.text = "Tie!";
            }

            Time.timeScale = 0;
        }
    }
Пример #2
0
    void Start()
    {
        spriteRenderer   = this.gameObject.GetComponent <SpriteRenderer>();
        soundSource      = GetComponent <AudioSource>();
        soundSource.clip = soundEffect;
        switch (type)
        {
        case PowerUpType.Health:
        case PowerUpType.Shield:
            healthHandler = GameObject.FindObjectOfType <HealthHandler>();
            break;

        case PowerUpType.Super_Edginess:
        case PowerUpType.Points:
            edginessHandler = GameObject.FindObjectOfType <EdginessHandler>();
            break;

        case PowerUpType.Bullet:
            polyShooter = GameObject.FindObjectOfType <PolyShooter>();
            break;

        default:
            Destroy(this);
            break;
        }
        powerUpManager = GameObject.FindObjectOfType <PowerUpManager>();

        StartCoroutine(FadePowerUp());
        Invoke("DestroySelf", 10f);
    }
Пример #3
0
    private void Awake()
    {
        character     = GetComponent <Character>();
        healthHandler = GetComponent <HealthHandler>();
        healthHandler.SetMaxHealth(character.maxHealth);

        movementType           = Character.MovementType.MoveToPoint;
        character.movementType = movementType;


        foreach (Transform point in patrolPointsObject.GetComponentInChildren <Transform>())
        {
            patrolPoints.Add(point.position);
        }

        machine             = GetComponentInChildren <StateMachine>();
        character.stateList = new List <State>()
        {
            new State_Idle(character),
            new State_Patrol(character, patrolPoints, patrolPointsObject.transform, roamRadius, patrolType),
            new State_Chase(character),
            new State_Search(character, this, 100f, 10f),
            new State_Attack(character),
            new State_Interact(character),
        };


        character.stateMachine            = machine;
        character.stateMachine.startState = character.stateList[0];
        //machine.SetState(stateList[1]);
    }
Пример #4
0
    public IEnumerator LoseTarget(float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        targetEnemy  = null;
        targetHealth = null;
    }
Пример #5
0
 // Start is called before the first frame update
 void Start()
 {
     health        = 100.0f;
     initialTime   = Time.time;
     healthHandler = GameObject.FindObjectOfType <HealthHandler>();
     healthHandler.updateSlider();
 }
    private void OnSceneLoaded(Scene loadedScene, LoadSceneMode loadSceneMode)
    {
        switch (loadedScene.buildIndex)
        {
        // Main Menu
        case 0:
            //GameObject.Find("Start Button").GetComponent<Button>().onClick.AddListener(() => StartGame());
            break;

        // In-game
        case 1:
            m_pauseMenu           = GameObject.FindGameObjectWithTag("PauseMenu");
            m_skillMenu           = GameObject.FindGameObjectWithTag("SkillMenu");
            m_skillMenuBackground = GameObject.Find("SkillMenuBackground");
            m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <BaseCharacter>().m_healthHandler;
            m_pauseMenu.SetActive(false);
            m_skillMenu.SetActive(false);
            m_skillMenuBackground.SetActive(false);
            break;

        case 2:
            GameObject.Find("Return").GetComponent <Button>().onClick.AddListener(() => QuitToMainMenu());
            break;
        }
        Debug.Log("Level Loaded");
    }
 // Start is called before the first frame update
 void Start()
 {
     player       = FindObjectOfType <PlayerController>();
     health       = GetComponent <HealthHandler>();
     scoreHandler = FindObjectOfType <ScoreHandler>();
     AddNoneTriggerBoxCollider();
 }
Пример #8
0
    public void spawnCharacter()
    {
        GameObject g = Instantiate(character, gameObject.transform.position, gameObject.transform.rotation);

        p1Controls = g.GetComponent <P1_MovementController> ();
        p2Controls = g.GetComponent <P2_MovementController> ();
        ProjectileReceiver pr = g.GetComponent <ProjectileReceiver> ();
        HealthHandler      hh = g.GetComponent <HealthHandler> ();

        if (gameObject.name == "P1Spawner")
        {
            p1Controls.enabled = true;

            p1Controls.specialSlider = specialSlider;
            p1Controls.shieldSlider  = shieldSlider;

            p2Controls.enabled = false;
            Destroy(g.GetComponent <P2_MovementController>());
        }
        if (gameObject.name == "P2Spawner")
        {
            p1Controls.enabled = false;

            p2Controls.specialSlider = specialSlider;
            p2Controls.shieldSlider  = shieldSlider;

            p2Controls.enabled = true;
            Destroy(g.GetComponent <P1_MovementController>());
        }
        pr.buffSlide    = bufferSlider;
        pr.bufferText   = bufferText;
        hh.healthSlider = healthSlider_ref;
    }
    private void Start()
    {
        health       = new HealthHandler(enemyProperties.totalHealth);
        health.Died += OnDied;

        GameManager.Instance.GameEnd += OnGameEnd;
    }
Пример #10
0
 // Start is called before the first frame update
 void Start()
 {
     healthScript   = GameObject.FindGameObjectWithTag("GameHandler").GetComponent <HealthHandler>();
     control        = GameObject.FindGameObjectWithTag("Player").GetComponent <Control>();
     engineScript   = GameObject.Find("EngineParent").GetComponent <EngineEvent>();
     dialogueScript = GameObject.Find("QuestionHandler").GetComponent <Dialogue>();
 }
Пример #11
0
 // Start is called before the first frame update
 protected virtual void Start()
 {
     soundSource      = GetComponent <AudioSource>();
     soundSource.clip = soundEffect;
     player           = GameObject.FindObjectOfType <PlayerMovement>().transform;
     edginessHandler  = GameObject.FindObjectOfType <EdginessHandler>();
     healthHandler    = GameObject.FindObjectOfType <HealthHandler>();
 }
Пример #12
0
 // Start is called before the first frame update
 void Start()
 {
     _health   = this.gameObject.GetComponent <HealthHandler>();
     _method   = OnDeath;
     _renderer = this.gameObject.GetComponent <SpriteRenderer>();
     _health.RegisterDeathMethod(_method);
     _defend.Add(this);
 }
Пример #13
0
 // Use this for initialization
 void Start()
 {
     _PlayerLives = GameObject.FindGameObjectWithTag("Player").GetComponent <HealthHandler> ();
     if (_PlayerLives == null)
     {
         print("No PlayerLives Detected in Scene @SceneManager");
     }
 }
Пример #14
0
 void Start()
 {
     spawner     = GetComponent <Respawn> ();
     rb          = GetComponent <Rigidbody>();
     col2D       = GetComponent <Collision>();
     hp          = GetComponent <HealthHandler>();
     facingRight = true;
 }
Пример #15
0
 private int _currentLives;                                                  //private variable of current lives
 // Use this for initialization
 void Start()
 {
     _lives = GameObject.Find(_target).GetComponent <HealthHandler> ();              //Find the Target GameObject
     if (_lives == null)                                                             //If there is no Lives found
     {
         print("NO " + _target + " FOUND IN SCENE! @HealthUI");                      //Print Error if the are no Lives found
     }
 }
Пример #16
0
    void Start()
    {
        InARange      = false;
        healthHandler = GameObject.Find("Scripts").GetComponent <HealthHandler>();
        Damage        = 3f;

        StartCoroutine(InRange());
    }
Пример #17
0
 // Use this for initialization
 void Start()
 {
     _input     = GameObject.Find("GameController").GetComponent <InputHandler> ();
     _health    = GetComponent <HealthHandler> ();
     _move      = GetComponent <MovementHandler> ();
     _shoot     = GetComponent <ShootHandler> ();
     _collision = GetComponent <CollisionHandler> ();
 }
Пример #18
0
        public static void AddHealth(Component entity, int health)
        {
            HealthHandler handler = entity.GetComponent <HealthHandler>();

            if (handler)
            {
                handler.AddHealth(health);
            }
        }
Пример #19
0
    public void Construct(Navigator navigator, HealthHandler healthHandler, BehaviorHandler behaviorHandler, Player player)
    {
        _navigator       = navigator;
        _healthHandler   = healthHandler;
        _behaviorHandler = behaviorHandler;
        _player          = player;

        return;
    }
Пример #20
0
 public void AssignTarget(Transform targetT)
 {
     if (targetEnemy == null)
     {
         targetEnemy  = targetT;
         targetHealth = targetEnemy.GetComponent <HealthHandler>();
         StartCoroutine(LoseTarget(changeTargetInterval));
     }
 }
Пример #21
0
    // Update is called once per frame
    void Update()
    {
        // left mouse button click
        if (playerScript)
        {
            if (Input.GetButtonDown("Fire1") | Input.GetButton("Fire1"))
            {
                if (Time.time > lastFireTime + 1 / frequency)
                {
                    // Spawn visual bullet

                    //Quaternion tempRot =  Quaternion.LookRotation(playerScript.GetMouseOnPlane() - muzzlePosition.position , Vector3.forward);
                    //tempRot.z = 0f;
                    //tempRot.w = 0.5f;

                    Quaternion tempRot = transform.parent.transform.rotation;

                    Quaternion   coneRandomRotation = Quaternion.Euler(Random.Range(-coneAngle, coneAngle), Random.Range(-coneAngle, coneAngle), 0);
                    GameObject   go     = (GameObject)Instantiate(bulletPrefab, muzzlePosition.position, tempRot * coneRandomRotation);
                    SimpleBullet bullet = go.GetComponent <SimpleBullet> ();

                    muzzleParticle.Emit(1);

                    lastFireTime = Time.time;

                    // Find the object hit by the raycast
                    RaycastHit hitInfo = new RaycastHit();
                    Physics.Raycast(transform.position, transform.parent.forward, out hitInfo, 100);

                    if (hitInfo.transform)
                    {
                        // Get the health component of the target if any
                        HealthHandler targetHealth = hitInfo.transform.GetComponent <HealthHandler> ();

                        if (targetHealth & (hitInfo.transform.root != transform.root))
                        {
                            // Apply damage
                            targetHealth.DeductHealth(Mathf.FloorToInt(damagePerSecond / frequency));
                        }

                        // Get the rigidbody if any
                        if (hitInfo.rigidbody)
                        {
                            // Apply force to the target object at the position of the hit point
                            Vector3 force = transform.forward * (forcePerSecond / frequency);
                            hitInfo.rigidbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse);
                        }
                        bullet.dist = hitInfo.distance;
                    }
                    else
                    {
                        bullet.dist = 1000;
                    }
                }
            }
        }
    }
Пример #22
0
 void Start()
 {
     debounce = false;
     delta    = 0f;
     _health  = gameObject.GetComponent <HealthHandler>();
     _method  = DeathMethod;
     _health.RegisterDeathMethod(_method);
     _collider = this.gameObject.GetComponent <BoxCollider2D>();
 }
Пример #23
0
 public void FindTarget()
 {
     if (target)
     {
         RaycastHit hit;
         if (Physics.Raycast(AutoTurretPos.position, ((target.GetBody.position + Vector3.up) - AutoTurretPos.position).normalized, out hit, AutoTurretRange, AutoTurretSightMask))
         {
             if (hit.transform != target)
             {
                 target = null;
             }
         }
         else
         {
             target = null;
         }
         if (target && target.isDead)
         {
             target = null;
         }
     }
     if (target)
     {
         return;
     }
     Collider[] colliders = Physics.OverlapSphere(AutoTurretPos.position, AutoTurretRange, AutoTurretMask);
     foreach (var item in colliders)
     {
         RaycastHit hit;
         if (Physics.Raycast(AutoTurretPos.position, ((item.transform.position + Vector3.up) - AutoTurretPos.position).normalized, out hit, AutoTurretRange, AutoTurretSightMask))
         {
             if (hit.collider == item)
             {
                 HealthHandler handler = item.GetComponent <HealthHandler>();
                 if (!handler)
                 {
                     ColliderHit hitCollider = item.GetComponent <ColliderHit>();
                     if (hitCollider)
                     {
                         handler = hitCollider.healthScript;
                     }
                 }
                 if (!handler)
                 {
                     continue;
                 }
                 if (handler.isDead)
                 {
                     continue;
                 }
                 target = handler;
                 return;
             }
         }
     }
 }
Пример #24
0
    private Vector3 _velocityState;                                     //Private Vector3 for the current Velocity


    // Use this for initialization
    void Start()
    {
        _input          = GameObject.Find("GameController").GetComponent <InputHandler> ();     //Find the GameControllers InputHandler
        _health         = GetComponent <HealthHandler> ();                                      //Find the HealthHandler
        _healthAnimator = GetComponent <HealthAnimator>();
        _move           = GetComponent <MovementHandler> ();                                    //Find the MovementHandler
        _shoot          = GetComponentInChildren <WeaponsInputProcessor> ();                    //Find the ShootHandler
        _trigger        = GetComponent <TriggerHandler> ();                                     //Find the TriggerHandler
        _collision      = GetComponent <CollisionHandler>();
    }
Пример #25
0
    private void SetHealthInUI(HealthHandler handler)
    {
        for (var i = 0; i < handler.MaxHealth; i++)
        {
            var healthState = i < handler.Health;
            thumbs[i].gameObject.SetActive(healthState);
        }

        amount.text = $"x{handler.Health}";
    }
    private void Awake()
    {
        health = new HealthHandler(PlayerProperties.playerTotalHealth);
        health.HealthUpdate += OnHealthUpdate;
        health.Died         += OnPlayerDied;
        OnHealthUpdate(PlayerProperties.playerTotalHealth);
        weaponFactory = new WeaponFactory();

        IntializeStateMachine();
    }
Пример #27
0
 private void Awake()
 {
     m_LocalNetworkTogglables = GetComponent <LocalNetworkTogglables>();
     m_PlayerNetworkHandler   = GetComponent <PlayerNetworkHandler>();
     m_RevealActor            = GetComponent <RevealActor>();
     m_StealthActor           = GetComponent <StealthActor>();
     m_SkillHandler           = GetComponent <SkillHandler>();
     m_HealthHandler          = GetComponent <HealthHandler>();
     m_CharacterCustomizer    = GetComponentInChildren <CharacterCustomizer>();
 }
Пример #28
0
        public static bool DeductHealth(Component entity, int health)
        {
            HealthHandler handler = entity.GetComponent <HealthHandler>();

            if (handler)
            {
                return(handler.DeductHealth(health));
            }
            return(false);
        }
    // Start is called before the first frame update
    void Start()
    {
        if (m_player == null)
        {
            m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
        }

        m_healthHandler = m_player.m_healthHandler;
        m_levelHandler  = m_player.m_levelHandler;
    }
Пример #30
0
    // Use this for initialization
    void Start()
    {
        gameObject.tag = "Player 2";
        FlipFacing();
        anim                   = GetComponent <Animator> ();
        rb                     = GetComponent <Rigidbody2D> ();
        stats                  = GetComponent <CharTraits> ();
        maxSpeed               = stats.walkspeed;
        jumpHeight             = stats.jumpheight;
        projectile             = stats.projectile;
        shieldSlider.maxValue  = 5.0f;
        specialSlider.maxValue = 5.0f;
        specialSlider.value    = specialSlider.maxValue;

        p1 = GameObject.FindGameObjectWithTag("Player 1");
        if (p1 != null)
        {
            Debug.Log("p1 isn't null");
            if (p1.gameObject.GetComponent <P1_MovementController> ().p2 == null)
            {
                Debug.Log("Trying to manually set p1 through p2");
                p1.gameObject.GetComponent <P1_MovementController> ().p2 = gameObject;
                if (p1.gameObject.GetComponent <P1_MovementController> ().p2 == gameObject)
                {
                    Debug.Log("Successfully set p1's reference to p2. Manually resetting p1's p2Health");
                    p1.gameObject.GetComponent <P1_MovementController> ().p2Health = gameObject.GetComponent <HealthHandler> ();
                }
            }
            p1Health = p1.GetComponent <HealthHandler> ();
            Debug.Log("p1 health is " + p1Health);
        }
        else
        {
            Debug.Log("p1 is null!");
        }

        // TOTAL BULL SHIT WORK AROUND
        p1.GetComponent <P1_MovementController>().p2 = gameObject;


        foreach (Transform child in transform)
        {
            GameObject g = (GameObject)(child.gameObject);
            // Debug.Log ("Found game object " + g.name + " in P2");


            g.tag = "Player 2 ext";
            foreach (Transform grandchild in g.transform)
            {
                grandchild.gameObject.tag = "Player 2 ext";
            }
        }
    }
Пример #31
0
 void Start()
 {
     target = GameObject.FindWithTag ("Player").transform;
     healtScript = (HealthHandler)target.GetComponent<HealthHandler>();
     myAgent = GetComponent<NavMeshAgent>();
 }