Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     for (int i = 0; i < begin - 1; i++)
     {
         AddPart();
     }
     ammo = spawn.GetComponent <PlayerShootScript>();
 }
Beispiel #2
0
 private void Shoot(GameState state)
 {
     if (_shootScript == null || _shootScript.IsFinished)
     {
         _shootScript = new PlayerShootScript();
         _shootScript.AddTarget(Thrombus);
         //state.AddScript(_shootScript);
     }
 }
    // Use this for initialization
    void Start()
    {
        cameraController = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraController>();
        cameraController.NewPlayer();
        Flash       = Gun.transform.GetComponentInChildren <ParticleSystem>();
        NewPosition = transform.position;
        shootScript = GetComponent <PlayerShootScript>();
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        playerStats     = player.GetComponent <PlayerStats>();
        healthScript    = player.GetComponent <HealthScript>();
        grabPlayerStats = GameObject.FindGameObjectWithTag("PlayerStats").GetComponent <GrabPlayerStats>();
        grabPlayerStats.NewPlayer();
        Flash.Stop();
        //Grabbing Necassary Components
        MyAnimator   = GetComponent <Animator>();
        NavMeshAgent = GetComponent <NavMeshAgent>();

        //Setting state to Idle
        EPlayerState = PlayerState.Idle;

        StartCoroutine(Alive());
    }
Beispiel #4
0
        private void ShootReaction(GameState state)
        {
            if (StartPosition - state.Player.WorldPosition.X > AttackRange)
            {
                return;
            }

            if (_playerAttackScript == null || _playerAttackScript.IsFinished)
            {
                _playerAttackScript = new PlayerShootScript();
                for (int index = 0; index < Enemies.Count; index++)
                {
                    _playerAttackScript.AddTarget(Enemies[index]);
                }

                //state.AddScript(_playerAttackScript);
            }
        }
Beispiel #5
0
 private void Start()
 {
     motor     = GetComponent <PlayerMotor>();
     PS_Script = Gun.GetComponent <PlayerShootScript>();
 }
    IEnumerator Alive()
    {
        while (IsAlive)
        {
            switch (EPlayerState)
            {
            case PlayerState.Idle:

                if (canShoot())
                {
                    if (!shootScript)
                    {
                        shootScript = GetComponent <PlayerShootScript>();
                    }
                    shootScript.Shoot();
                }

                MyAnimator.SetFloat("VSpeed", 0);
                break;

            case PlayerState.Moving:
                MyAnimator.SetFloat("VSpeed", 1);
                if (Vector3.Distance(NewPosition, transform.position) > WalkRange)
                {
                    Move();
                }
                else
                {
                    MyAnimator.SetFloat("VSpeed", 0);
                    EPlayerState = PlayerState.Idle;
                }
                break;

            case PlayerState.Shooting:
                if (canShoot())
                {
                    if (!shootScript)
                    {
                        shootScript = GetComponent <PlayerShootScript>();
                    }
                    shootScript.Shoot();
                }
                else
                {
                    EPlayerState = PlayerState.Idle;
                }

                break;

            case PlayerState.Building:
                break;

            case PlayerState.Harvesting:
                if (Target != null)
                {
                    //if within range of resource
                    if (Vector3.Distance(Target.transform.position, transform.position) <= HarvestRange)
                    {
                        MyAnimator.SetFloat("VSpeed", 0);
                        //if harvest cool down is 0
                        if (HarvestCoolDown <= 0.0f)
                        {
                            //run harvest animation
                            Target.transform.gameObject.GetComponent <ResourceScript>().ResourceCount -= playerStats.HarvestAmount;
                            Target.transform.gameObject.GetComponent <ResourceScript>().Hit();
                            if (Target.transform.Find("Wood"))
                            {
                                Target.GetComponent <AudioSource>().Play();
                                grabPlayerStats.UpdateWood();
                                playerStats.Wood += playerStats.HarvestAmount;
                            }
                            if (Target.transform.Find("Stone"))
                            {
                                grabPlayerStats.UpdateStone();
                                playerStats.Stone += playerStats.HarvestAmount;
                            }
                            HarvestCoolDown = 0.5f;
                        }
                    }
                    else     //If out of range, run towards it
                    {
                        MyAnimator.SetFloat("VSpeed", 1);
                        NewPosition = Target.transform.position;
                        Move();
                    }
                }
                else
                {
                    EPlayerState = PlayerState.Idle;
                }
                break;

            case PlayerState.Dead:
                Destroy(gameObject);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            yield return(null);
        }
        Destroy(gameObject);
    }