Пример #1
0
    protected override void Start()
    {
        base.Start();

        type       = "Player";
        enemyCount = 0;
        controller = GetComponent <CharacterController>();
        cam        = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        gun        = transform.GetChild(0).gameObject;
        muzzle     = gun.transform.GetChild(2);
        grip       = gun.transform.GetChild(0);
        status     = AimStatus.HIP;
        anim       = gun.GetComponent <Animation>();
        animState  = anim["ADS"];
    }
Пример #2
0
    void FixedUpdate()
    {
        staminaManagement();
        //transform.rotation = Quaternion.Euler(cam.transform.rotation.eulerAngles.x, cam.transform.rotation.eulerAngles.y, cam.transform.rotation.eulerAngles.z);
        ManageUI();
        JumpAndGravity();
        // Basic movement for the player
        // Only move if input from the axis are detected
        if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
        {
            Move();
        }

        // plays an animation so that the player aims down the sight when they are holding down the
        // right mouse button
        if (Input.GetMouseButtonDown(1) && status != AimStatus.AIM && !anim.IsPlaying("ADS"))
        {
            status          = AimStatus.AIM;
            animState.speed = 1;
            anim.Play("ADS");
        }
        if (Input.GetMouseButtonUp(1) && status == AimStatus.AIM && !anim.IsPlaying("ADS"))
        {
            status          = AimStatus.HIP;
            animState.speed = -1;
            animState.time  = animState.length;
            anim.Play("ADS");
        }

        // Single fire, could be auto as well if you guys want, but since the player is using a pistol
        // this might be a good challenge for them (I hope).
        // (change conditional statement to Input.GetMouseButton(0) for auto fire)
        if (Input.GetMouseButtonDown(0) && ammo > 0 && !isReloading)
        {
            Shoot();
        }

        // Reload the weapon if the amount of bullets in the magazine is less than maxAmmo.
        // Simulate reloading time by invoking the method after a pre-determined time.
        if (Input.GetKeyDown(KeyCode.R) && ammo < maxAmmo && !isReloading)
        {
            isReloading = true;
            Destroy(Instantiate(magazine, grip.position, grip.rotation), 5);
            Invoke("ReloadWeapon", 1);
            Debug.Log("Reloading...");
        }

        // Update where the player is looking at
        LookAtPoint();

        // kill the player if they fell off of the map
        if (transform.position.y < -10)
        {
            TakeDamage(1000);
        }

        if (health < startingHealth)
        {
            health += 2.5F * Time.deltaTime;
            health  = health > startingHealth ? startingHealth : health;
        }
    }