Beispiel #1
0
 //bullet hits something
 void OnCollisionEnter(Collision hit)
 {
     if (networkView.isMine)
     {
         if (hit.transform.gameObject.name == "Enemy(Clone)")
         {
             EnemyScript script = hit.gameObject.GetComponent("EnemyScript") as EnemyScript;
             script.rpcGetHit(ad, sd);
         }
         if (hit.transform.gameObject.name == "EnemyTank(Clone)")
         {
             EnemyTankScript script = hit.gameObject.GetComponent("EnemyTankScript") as EnemyTankScript;
             script.rpcGetHit(ad, sd);
         }
         if (hit.transform.gameObject.name == "EnemyBomber")
         {
             EnemyBomberScript script = hit.gameObject.GetComponent("EnemyBomberScript") as EnemyBomberScript;
             script.rpcGetHit(ad, sd);
         }
         destroy();
     }
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (life > 0)
        {
            life -= Time.deltaTime;

            //check if bullet will hit anything in front of it because bullet moves too fast
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, checkahead))
            {
                if (hit.transform.gameObject.tag == "Objective")
                {
                    Debug.Log("objective hit");
                }
                if (hit.transform.gameObject.name == "Enemy(Clone)")
                {
                    EnemyScript script = hit.transform.gameObject.GetComponent("EnemyScript") as EnemyScript;
                    script.rpcGetHit(ad, sd);
                }
                if (hit.transform.gameObject.name == "EnemyTank(Clone)")
                {
                    EnemyTankScript script = hit.transform.gameObject.GetComponent("EnemyTankScript") as EnemyTankScript;
                    script.rpcGetHit(ad, sd);
                }
                if (hit.transform.gameObject.name == "EnemyBomber")
                {
                    EnemyBomberScript script = hit.transform.gameObject.GetComponent("EnemyBomberScript") as EnemyBomberScript;
                    script.rpcGetHit(ad, sd);
                }
                destroy();
            }
        }

        else
        {
            destroy();
        }
    }