예제 #1
0
파일: Gun.cs 프로젝트: nirvanalab/Jagadam
    protected void Fire()
    {
        if (ammoManager.HasAmmo(tag))
        {
            fireBullet();
            //play sound
            GetComponent <AudioSource>().PlayOneShot(liveFire);
            ammoManager.ConsumeAmmo(tag);
            UpdateAmmoText();
        }
        else
        {
            GetComponent <AudioSource>().PlayOneShot(dryFire);
        }

        GetComponentInChildren <Animator>().Play("Fire");

        // Debug.Log("Fire");
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        float probability = Time.deltaTime * shotsPerSecond;

        if (Random.value < probability && GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Idle") && canFire && ammoManager.HasAmmo())
        {
            //Instantiate
            GameObject firedProjectile = Instantiate(projectile, new Vector3(transform.GetChild(0).position.x, transform.GetChild(0).position.y, -0.5f), Quaternion.identity);
            firedProjectile.GetComponent <Projectile>().EnemyParent = gameObject;

            //Set Color
            firedProjectile.GetComponent <SpriteRenderer>().color = GetComponent <SpriteRenderer>().color;
            firedProjectile.GetComponent <Light>().color          = GetComponent <SpriteRenderer>().color;

            //Set trail Color
            firedProjectile.GetComponent <TrailRenderer>().startColor = GetComponent <SpriteRenderer>().color;
            firedProjectile.GetComponent <TrailRenderer>().endColor   = GetComponent <SpriteRenderer>().color;

            // Set Projectile velocity
            float speed = firedProjectile.GetComponent <Projectile>().ProjectileSpeed;
            firedProjectile.GetComponent <Projectile>().ProjectileVelocity = player.transform.position - transform.GetChild(0).position;

            canFire = false;
            ammoManager.DecreaseAmmo();
        }
        //if (Input.GetKeyDown(KeyCode.Space))
        //{
        //    DestroyEnemy();
        //}
    }
예제 #3
0
 bool HasAmmo()
 {
     return(ammoManager.HasAmmo(ammoType));
 }