Пример #1
0
    void DamagePlayer()
    {
        PlayerDamageHandler playerDamageHandler = GameObject.Find("Player").GetComponent <PlayerDamageHandler>();

        if (playerDamageHandler == null)
        {
            Debug.Break();
            throw new MissingComponentException("PlayerDamageHandler script could not be found!\nCheck that the script is attached to Player");
        }
        else
        {
            playerDamageHandler.DamagePlayer();
        }
    }
Пример #2
0
    void OnTriggerEnter(Collider other)
    {
        if (!isInvincible)
        {
            bool hitByWeapon = false;

            //sword damage
            if (other.gameObject.tag == "Sword")
            {
                hitByWeapon = true;
                if (other.transform.parent.parent.gameObject.GetComponent <PlayerTeamInfo>().GetTeam() != playerTeamInfo.GetTeam())
                {
                    if (GetComponent <PlayerSteeringMode>().GetSteeringMode())
                    {
                        if (!pushBack)
                        {
                            StartCoroutine(PushBackTime());
                            GiveUpShipOnHit(other.transform.parent.gameObject.GetComponent <Sword>().GetPlayerForward());
                        }
                    }
                    else
                    {
                        if (!pushBack)
                        {
                            StartCoroutine(PushBackTime());
                            StartCoroutine(StopMovement(other.transform.parent.gameObject.GetComponent <Sword>().GetPlayerForward()));
                        }
                    }
                }
            }

            if (hitByWeapon)
            {
                // Get the weapon's Joe
                attacker       = other.transform.parent.parent.gameObject;
                nameOfAttacker = attacker.name;
                timeOfAttack   = Time.time;

                PlayerDamageHandler damageHandler = this.GetComponent <PlayerDamageHandler> ();
                damageHandler.attacker     = attacker;
                damageHandler.timeOfAttack = timeOfAttack;
            }
        }
    }
Пример #3
0
    //getting the closest player to this object if the player moves past a distance set above
    void FindClosestPlayer()
    {
        float closest = Mathf.Infinity;

        foreach (GameObject child in players)
        {
            if (!child.GetComponent <PlayerDamageHandler>().Alive)
            {
                continue;
            }

            //meant to skip the player if there isnt a path that can be made
            NavMeshPath testPath = new NavMeshPath();
            agent.CalculatePath(child.transform.position, testPath);
            if (testPath.status == NavMeshPathStatus.PathPartial)
            {
                skippedPlayers++;
                continue;
            }


            float curDistance = Vector3.Distance(transform.position, child.transform.position);
            if (!isDead)
            {
                if (curDistance < closest && !agent.isStopped)
                {
                    hasTarget         = true;
                    closest           = curDistance;
                    currentPlayer     = child.GetComponent <PlayerDamageHandler>();
                    agent.destination = currentPlayer.transform.position;
                }
            }
        }
        if (skippedPlayers >= players.Length)
        {
            hasTarget = false;
        }
        skippedPlayers = 0;
    }
Пример #4
0
 void Awake()
 {
     pControl       = GetComponent <PlayerControl>();
     pDamageHandler = GetComponent <PlayerDamageHandler>();
 }