Пример #1
0
 void Start()
 {
     playerHealth   = GetComponent <PlayerHealth>();
     anim           = GetComponent <Animator>();
     playerMovement = GetComponent <PlayerMovement>();
     weaponShoot    = shooter.GetComponent <WeaponShoot>();
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        float inputX = Input.GetAxis("Horizontal2");
        float inputY = Input.GetAxis("Vertical2");

        movement = new Vector2(
            speed.x * inputX,
            speed.y * inputY);

        // Astuce pour ceux sous Mac car Ctrl + flèches est utilisé par le système
        Shield2 shield = GetComponentInChildren <Shield2>();

        if (Input.GetButton("Fire2"))
        {
            shield.Protect(movement);
        }
        if (Input.GetButton("RotaD2"))
        {
            shield.RotaGauche();
        }
        if (Input.GetButton("RotaG2"))
        {
            shield.RotaDroite();
        }
        WeaponShoot weapon = GetComponent <WeaponShoot>();

        if (weapon != null)
        {
            // false : le joueur n'est pas un ennemi
            weapon.Attack(false, 0);
        }
        var dist = (transform.position - Camera.main.transform.position).z;

        var leftBorder = Camera.main.ViewportToWorldPoint(
            new Vector3(0, 0, dist)
            ).x;

        var rightBorder = Camera.main.ViewportToWorldPoint(
            new Vector3(1, 0, dist)
            ).x;

        var topBorder = Camera.main.ViewportToWorldPoint(
            new Vector3(0, 0, dist)
            ).y;

        var bottomBorder = Camera.main.ViewportToWorldPoint(
            new Vector3(0, 1, dist)
            ).y;

        transform.position = new Vector3(
            Mathf.Clamp(transform.position.x, leftBorder, rightBorder),
            Mathf.Clamp(transform.position.y, topBorder, bottomBorder),
            transform.position.z
            );
    }
Пример #3
0
    private void Start()
    {
        collider         = GetComponent <SphereCollider>();
        collider.enabled = false;

        shooter     = GameObject.FindGameObjectWithTag("Fire");
        weaponShoot = shooter.GetComponent <WeaponShoot>();

        playerGO     = GameObject.FindGameObjectWithTag("Player");
        playerHealth = playerGO.GetComponent <PlayerHealth>();
    }
Пример #4
0
 // Set the selected weapon to active(true) and others to active(false)
 void SwitchWeapon(int weapon)
 {
     for (int i = 0; i < nrWeapons; i++) {
         if (i == weapon) {
             weapons[i].gameObject.SetActive(true);
             weaponShoot = weapons[i].gameObject.GetComponentInChildren<WeaponShoot>();
         } else {
             weapons[i].gameObject.SetActive(false);
         }
         weaponShoot.UpdateUI();
         weaponShoot.ApplyUpgrades();
     }
 }
Пример #5
0
    //  public Canvas gameoverCanvas;

    void Awake()
    {
        // Setting up the references.
        anim           = GetComponent <Animator>();
        playerAudio    = GetComponent <AudioSource>();
        playerMovement = GetComponent <FirstPersonController>();
        playerShooting = GetComponentInChildren <WeaponShoot>();

        // Set the initial health of the player.
        currentHealth = startingHealth;

        Enemy = GameObject.FindGameObjectsWithTag("Enemy");



        Cursor.visible   = false;
        Cursor.lockState = CursorLockMode.Locked;
    }
Пример #6
0
    void Start()
    {
        canDie       = true;
        playerHealth = GetComponent <PlayerHealth>();
        player       = GetComponent <Player>();

        cam         = camara.GetComponent <Camera>();
        weaponShoot = player.shooter.GetComponent <WeaponShoot>();

        cameraT = Camera.main.transform;

        animator = GetComponent <Animator>();

        walkSpeed           = 2;
        runSpeed            = 6;
        turnSmoothTime      = 0.2f;
        turnSmoothVelocity  = 0;
        speedSmoothTime     = 0.1f;
        speedSmoothVelocity = 0;
        currentSpeed        = 0;
    }
Пример #7
0
    private void Awake()
    {
        Owner = GetComponent<Actor>();
        QueueLocators = new Queue<GameObject>(ShootLocators);
        m_hPool = GlobalFactory.GetPool(BulletPrefab);

        //Automatic State Machine Composition
        //One Ready State
        m_hTrigger = new WeaponReady();

        //N Wait And Shoot for Barrage Implemenation
        IWeaponState hLast = m_hTrigger;

        if (BulletDelay > 0f)
        {
            for (int i = 0; i < Barrage; i++)
            {
                WeaponShoot hShoot = new WeaponShoot(this, Mode);
                WeaponWait hWait = new WeaponWait(BulletDelay);
                hLast.Next = hShoot;
                hShoot.Next = hWait;
                hLast = hWait;
            }
        }
        else
        {
            WeaponShoot hShoot = new WeaponShoot(this, Barrage, Mode);
            WeaponWait hWait = new WeaponWait(BulletDelay);
            hLast.Next = hShoot;
            hShoot.Next = hWait;
            hLast = hWait;
        }


        (hLast as WeaponWait).Delay = BarrageDelay;
        hLast.Next = m_hTrigger;
        m_hStateMachine = hLast;
    }
Пример #8
0
 public void SetWeaponShootOwner(WeaponShoot newWeaponShoot)
 {
     whichWeapon = newWeaponShoot;
 }
Пример #9
0
 public void SetHowMuch(int hm, WeaponShoot ww)
 {
     howMuchAmmo = hm;
     whichWeapon = ww;
 }
Пример #10
0
    // Update is called once per frame
    void Update()
    {
        // Drop weapon when 'T' is pressed
        if (Input.GetKeyDown(KeyCode.T))
        {
            // Is there a weapon to drop
            if (weapon != null)
            {
                // Remove weapon as a Child of Player
                weaponAttach.transform.DetachChildren();

                // Turn collision back on
                StartCoroutine(EnableCollisions(1.0f));

                // Turn Physics back on
                weapon.GetComponent <Rigidbody>().isKinematic = false;

                // Throw Weapon forward
                weapon.GetComponent <Rigidbody>().AddForce(weapon.transform.forward * weaponDropForce, ForceMode.Impulse);

                ammoText.text = string.Empty;
            }
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            // Is there a weapon to drop
            if (weapon2 != null)
            {
                // Remove weapon as a Child of Player
                weaponAttach2.transform.DetachChildren();

                // Turn collision back on
                StartCoroutine(EnableCollisions(1.0f));

                // Turn Physics back on
                weapon2.GetComponent <Rigidbody>().isKinematic = false;

                // Throw Weapon forward
                weapon2.GetComponent <Rigidbody>().AddForce(weapon2.transform.forward * weaponDropForce, ForceMode.Impulse);

                ammoText.text = string.Empty;
            }
        }

        if (Input.GetKeyDown("1") && !isPrimaryWeapon && weapon != null)
        {
            isPrimaryWeapon = true;
            weapon.SetActive(true);
            if (weapon2.transform.parent == weaponAttach.transform)
            {
                weapon2.SetActive(false);
            }
        }
        else if (Input.GetKeyDown("2") && isPrimaryWeapon && weapon2 != null)
        {
            isPrimaryWeapon = false;
            weapon2.SetActive(true);
            if (weapon.transform.parent == weaponAttach.transform)
            {
                weapon.SetActive(false);
            }
        }


        // Check if the Fire key was pressed
        if (Input.GetButtonDown("Fire1"))
        {
            // Check if there is weapon attached to the Player
            if (weapon != null)
            {
                // Grab WeaponScript to fire projectile
                WeaponShoot ws = weapon.GetComponent <WeaponShoot>();
                if (ws)
                {
                    ammoText.text = ws.Shoot().ToString();
                }
            }
            else if (weapon2 != null)
            {
                WeaponShoot ws = weapon2.GetComponent <WeaponShoot>();
                if (ws)
                {
                    ammoText.text = ws.Shoot().ToString();
                }
            }
        }
    }
Пример #11
0
 public ShootAlternateA(WeaponShoot owner)
 {
     m_hOwner = owner;
 }
Пример #12
0
 public ShootSimultaneous(WeaponShoot owner)
 {
     m_hOwner = owner;
 }
Пример #13
0
 public ShootModeFactory(WeaponShoot owner)
 {
     ShootModes = new Dictionary<ShootMode, IShootStrategy>();
     ShootModes.Add(ShootMode.Simultaneous, new ShootSimultaneous(owner));
     ShootModes.Add(ShootMode.AlternateA,   new ShootAlternateA(owner));
     ShootModes.Add(ShootMode.AlternateB,   new ShootAlternateB());
 }