Exemplo n.º 1
0
    private void Fire()
    {
        shotCounter = timeBtweenShots;
        Bulletcontroller newbullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as Bulletcontroller;

        newbullet.speed = bulletSpeed;
    }
Exemplo n.º 2
0
    IEnumerator Fire()
    {
        currentAmmo--;
        shotCounter = timeBtweenShots;
        Bulletcontroller newbullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as Bulletcontroller;

        newbullet.speed = bulletSpeed;
        audio.PlayOneShot(audio.clip);
        yield return(new WaitForSeconds(3f));
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        float moveX = Input.GetAxisRaw("Horizontal");

        float moveY = Input.GetAxisRaw("Vertical");

        Vector2 position = rbody.position;
        //position.x += moveX * speed * Time.deltaTime;
        //position.y += moveY * speed * Time.deltaTime;可以删去

        Vector2 moveVector = new Vector2(moveX, moveY);

        if (moveVector.x != 0 || moveVector.y != 0)
        {
            lookDirection = moveVector;
        }

        if (isInvincible)

        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        anim.SetFloat("Look X", lookDirection.x);
        anim.SetFloat("Look Y", lookDirection.y);
        anim.SetFloat("Speed", moveVector.magnitude);

        position += moveVector * speed * Time.deltaTime;
        rbody.MovePosition(position);

        //==================子弹按下J键进行攻击=====================
        if (Input.GetKeyDown(KeyCode.J))
        {
            anim.SetTrigger("Launch");//播放攻击动画


            GameObject       bullet = Instantiate(bulletPrefab, rbody.position + Vector2.up * 0.5f, Quaternion.identity);
            Bulletcontroller bc     = bullet.GetComponent <Bulletcontroller>();
            if (bc != null)
            {
                bc.Move(lookDirection, 300);
            }
        }
    }