示例#1
0
    public void defaultShoot(bool isEnemy)
    {
        var shotTransform = Instantiate(shotPrefab) as Transform;

        shotTransform.position = transform.position;
        PlayerBulletScript shot = shotTransform.gameObject.GetComponent <PlayerBulletScript>();

        if (shot != null)
        {
            shot.isEnemyShot = isEnemy;
        }

        PulpyScript move = shotTransform.gameObject.GetComponent <PulpyScript>();

        if (move != null)
        {
            if (shootRight)
            {
                move.direction = this.transform.right;
            }
            else
            {
                move.direction = this.transform.right * -1;
            }
        }
    }
示例#2
0
    public void FireWeapon()
    {
        GameObject bullet = Instantiate(bulletPrefab);

        bullet.transform.position = transform.position;
        PlayerBulletScript bulletScript = bullet.GetComponent <PlayerBulletScript>();

        bulletScript.speed    = bulletSpeed;
        bulletScript.velocity = weaponTip.up;
        bulletScript.SetDamageInstance(damage.Copy());
    }
示例#3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PlayerBulletScript shot = other.gameObject.GetComponent <PlayerBulletScript>();

        if (shot != null && (invTimer >= invulerabilityTime))
        {
            if (shot.isEnemyShot != GetComponent <HealthScript>().isEnemy)
            {
                Damage(shot.damage);
                Destroy(shot.gameObject);
            }
        }
    }
示例#4
0
 // Update is called once per frame
 void Update()
 {
     if (networkView.isMine)
     {
         if (Input.GetKeyDown("1"))
         {
             weapon = 1;
         }
         if (Input.GetKeyDown("2"))
         {
             weapon = 2;
         }
         if (Input.GetMouseButton(0))
         {
             if (weapon == 1 && lastfire1 <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet1, transform.position + transform.forward * 2.3f + transform.up * -0.1f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad;
                 bs.sd         = sd;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force);
                 lastfire1 = FIRETIME1;
                 Transform s = Network.Instantiate(spark1, transform.position + transform.forward * 5.0f + transform.right * 1.0f + transform.up * -0.1f, Quaternion.identity, 0) as Transform;
             }
             if (weapon == 2 && lastfire2 <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet2, transform.position + transform.forward * 2.3f + transform.up * -0.1f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad2;
                 bs.sd         = sd2;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force);
                 lastfire2 = FIRETIME2;
                 Transform s = Network.Instantiate(spark2, transform.position + transform.forward * 5.0f + transform.right * 1.0f + transform.up * -0.1f, Quaternion.identity, 0) as Transform;
             }
         }
         if (lastfire1 > 0)
         {
             lastfire1 -= Time.deltaTime;
         }
         if (lastfire2 > 0)
         {
             lastfire2 -= Time.deltaTime;
         }
     }
 }
示例#5
0
 // Update is called once per frame
 void Update()
 {
     if (networkView.isMine)
     {
         if (Input.GetKeyDown("1"))
         {
             weapon = 1;
             //networkView.RPC("HideWeapon", RPCMode.AllBuffered, ad, sd);
             networkView.RPC("ShowWeapon", RPCMode.AllBuffered, "xm8");
             networkView.RPC("HideWeapon", RPCMode.AllBuffered, "rl");
         }
         if (Input.GetKeyDown("2"))
         {
             weapon = 2;
             networkView.RPC("HideWeapon", RPCMode.AllBuffered, "xm8");
             networkView.RPC("ShowWeapon", RPCMode.AllBuffered, "rl");
         }
         if (Input.GetKeyDown("3"))
         {
             weapon = 3;
             networkView.RPC("HideWeapon", RPCMode.AllBuffered, "xm8");
             networkView.RPC("ShowWeapon", RPCMode.AllBuffered, "rl");
         }
         if (Input.GetMouseButton(0))
         {
             if (weapon == 1 && lastfire1 <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet, transform.position + transform.forward * 0.9f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad1;
                 bs.sd         = sd1;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force);
                 lastfire1 = FIRETIME1;
                 Transform s = Network.Instantiate(spark, transform.position + transform.forward * 1.2f + transform.right * 0.1f - transform.up * 0.1f, Quaternion.identity, 0) as Transform;
             }
             if (weapon == 2 && lastfire2 <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet2, transform.position + transform.forward * 0.9f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad2;
                 bs.sd         = sd2;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force2);
                 lastfire2 = FIRETIME2;
                 Transform s = Network.Instantiate(spark, transform.position + transform.forward * 1.2f + transform.right * 0.1f - transform.up * 0.1f, Quaternion.identity, 0) as Transform;
             }
             if (weapon == 3 && lastfire3 <= 0)
             {
                 Transform           b  = Network.Instantiate(bullet3, transform.position + transform.forward * 0.9f, transform.rotation, 0) as Transform;
                 PlayerMissileScript bs = b.GetComponent("PlayerMissileScript") as PlayerMissileScript;
                 bs.ad     = ad3;
                 bs.sd     = sd3;
                 lastfire3 = FIRETIME3;
                 Transform s = Network.Instantiate(spark, transform.position + transform.forward * 1.2f + transform.right * 0.1f - transform.up * 0.1f, Quaternion.identity, 0) as Transform;
             }
         }
         if (lastfire1 > 0)
         {
             lastfire1 -= Time.deltaTime;
         }
         if (lastfire2 > 0)
         {
             lastfire2 -= Time.deltaTime;
         }
         if (lastfire3 > 0)
         {
             lastfire3 -= Time.deltaTime;
         }
     }
 }
示例#6
0
 // Update is called once per frame
 void Update()
 {
     if (networkView.isMine)
     {
         if (Input.GetKeyDown("1"))
         {
             weapon = 1;
         }
         if (Input.GetKeyDown("2"))
         {
             weapon = 2;
         }
         if (Input.GetKeyDown("3"))
         {
             weapon = 3;
         }
         if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space))
         {
             if (weapon == 1 && lastfire <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet, transform.position + transform.forward * 10.0f + transform.up * 1.5f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad;
                 bs.sd         = sd;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force);
                 lastfire = FIRETIME;
             }
             if (weapon == 2 && lastfire2 <= 0)
             {
                 Transform          b  = Network.Instantiate(bullet2, transform.position + transform.forward * 15.0f + transform.up * 1.5f, transform.rotation, 0) as Transform;
                 PlayerBulletScript bs = b.GetComponent("PlayerBulletScript") as PlayerBulletScript;
                 bs.ad         = ad2;
                 bs.sd         = sd2;
                 bs.checkahead = checkahead;
                 b.rigidbody.AddForce(transform.forward * force);
                 lastfire2 = FIRETIME2;
             }
             if (weapon == 3 && lastfire3 <= 0)
             {
                 Transform           b  = Network.Instantiate(bullet3, transform.position + transform.forward * 15.0f + transform.up * 1.5f, transform.rotation, 0) as Transform;
                 PlayerMissileScript bs = b.GetComponent("PlayerMissileScript") as PlayerMissileScript;
                 bs.ad     = ad3;
                 bs.sd     = sd3;
                 lastfire3 = FIRETIME3;
             }
         }
         if (lastfire > 0)
         {
             lastfire -= Time.deltaTime;
         }
         if (lastfire2 > 0)
         {
             lastfire2 -= Time.deltaTime;
         }
         if (lastfire3 > 0)
         {
             lastfire3 -= Time.deltaTime;
         }
     }
 }