コード例 #1
0
    protected override void makeAttack()
    {
        if (Time.time < nextTimeToFire)
        {
            return;
        }
        nextTimeToFire = Time.time + 1f / fireRate;
        GameObject nearest = null;

        GameObject[] objects = GameObject.FindGameObjectsWithTag(targetTag);
        foreach (GameObject item in objects)
        {
            if (item.GetComponent <Renderer>().isVisible)
            {
                if (nearest == null)
                {
                    nearest = item;
                    continue;
                }
                if (Vector3.Distance(airplane.position, item.transform.position)
                    <= Vector3.Distance(airplane.position, nearest.transform.position))
                {
                    nearest = item;
                }
            }
        }
        if (nearest != null)
        {
            BaseFire temp = createFire(rocketPrefab, throwPoint.transform.position, transform.rotation);
            temp.GetComponent <HomingMissileFire>().target = nearest.transform;
            Destroy(temp.gameObject, lifeTime);
        }
    }
コード例 #2
0
    protected override void makeAttack()
    {
        BaseFire  newBomb   = createFire(fireObject, transform.position + offset, transform.rotation);
        Rigidbody rigidbody = newBomb.GetComponent <Rigidbody>();
        Vector3   force     = (transform.forward - transform.up) * throwForce * Time.deltaTime;

        rigidbody.AddForce(force);
    }
コード例 #3
0
    protected override void makeAttack()
    {
        BaseFire  newBullet = createFire(bulletObject, transform.position + offset, transform.rotation);
        Rigidbody rigidbody = newBullet.GetComponent <Rigidbody>();
        Vector3   force     = transform.forward * fireForce * Time.deltaTime;

        rigidbody.AddForce(force);
    }
コード例 #4
0
    protected BaseFire createFire(BaseFire baseFire, Vector3 position, Quaternion rotation)
    {
        BaseFire fire = Instantiate(baseFire, position, rotation);

        fire.damage    = damage;
        fire.createdBy = transform.root.gameObject;
        ignoreCollideWithAirplane(fire);
        return(fire);
    }
コード例 #5
0
    private void OnCollisionEnter(Collision collision)
    {
        BaseFire fire = collision.collider.GetComponent <BaseFire>();

        if (fire != null && !fire.createdBy.CompareTag(gameObject.tag))
        {
            healthHandler.takdeDamage(fire.damage);
        }
    }
コード例 #6
0
    protected override void makeAttack()
    {
        BaseFire  temp = createFire(rocketPrefab, throwPoint.transform.position, transform.rotation * Quaternion.Euler(rocketRotation));
        Rigidbody rb   = temp.GetComponent <Rigidbody>();

        if (rb != null)
        {
            rb.AddForce(Quaternion.AngleAxis(rocketRotation.y, transform.up) * transform.forward * throwForce, ForceMode.VelocityChange);
        }
        Destroy(temp.gameObject, rocketLifeTime);
    }
コード例 #7
0
 protected void ignoreCollideWithAirplane(BaseFire fire)
 {
     Collider[] collidersInAirplane = transform.root.GetComponentsInChildren <Collider>();
     Collider[] collidersInFire     = fire.transform.root.GetComponentsInChildren <Collider>();
     foreach (var item1 in collidersInAirplane)
     {
         foreach (var item2 in collidersInFire)
         {
             Physics.IgnoreCollision(item1, item2, true);
         }
     }
 }
コード例 #8
0
        void AssignLastEnemyComponents()
        {
            lastEnemy = GameObject.Find(Names.Enemy);

            if (lastEnemy == null)
            {
                Debug.LogError("GameObject with Tag LastEnemy not found in LevelManager.cs!");
                return;
            }

            lastEnemyShip = lastEnemy.GetComponentInChildren <ShipHealth>();
            lastEnemyFire = lastEnemy.GetComponent <BaseFire>();
        }
コード例 #9
0
        void AssignPlayerComponents()
        {
            GameObject player = GameObject.Find(Names.Player);

            if (player == null)
            {
                Debug.LogError("GameObject with Tag Player not found in LevelManager.cs!");
                return;
            }

            playerShip     = player.GetComponentInChildren <ShipHealth>();
            playerMovement = player.GetComponent <IPlayerMovement>();
            playerFire     = player.GetComponent <PlayerFire>();
        }
コード例 #10
0
    protected override void makeAttack()
    {
        if (Time.time < nextTimeToFire)
        {
            return;
        }
        nextTimeToFire = Time.time + 1f / fireRate;
        muzzleFlash.Play();
        //90f, -7f, 0f
        BaseFire  bullet   = createFire(bulletPrefab, firePosition.transform.position, transform.rotation * Quaternion.Euler(bulletRotation));
        Rigidbody bulletRb = bullet.GetComponent <Rigidbody>();

        if (bulletRb != null)
        {
            bulletRb.AddForce(Quaternion.AngleAxis(bulletRotation.y, transform.up) * transform.forward * throwForce, ForceMode.VelocityChange);
        }

        Destroy(bullet.gameObject, bulletLifetime);
    }
コード例 #11
0
    void Start()
    {
        baseFire         = Instantiate(baseFire, Vector3.zero, Quaternion.identity);
        personCountBase  = personCount;
        stressResolution = "calm";
        diffusing        = false;
        diffusionFail    = false;
        charging         = false;
        chargeFail       = false;
        gridTarget       = new Vector2(-1f, -1f);
        rWTarget         = new Vector2(-1f, -1f);
        sideTracked      = false;
        GetComponent <Renderer>().sharedMaterial = materials[client];
        odin                   = GameObject.FindGameObjectsWithTag("odin")[0];
        baseFire.odin          = odin;
        baseFire.bulletManager = odin.GetComponent <BulletManager>();
        baseFire.shooterObject = gameObject;
        mover                  = GetComponent <Mover>();
        //personCountText = GetComponentInChildren<TextMesh>();
        //personCountText = transform.GetChild(1).GetComponent<TextMesh>();
        personCountText.text = personCount.ToString();
        //deployedIndexText = transform.GetChild(2).GetComponent<TextMesh>();

        commandHub = GameObject.FindGameObjectsWithTag("Player")[client].GetComponent <CommandHub>();
        commandHub.deployedUnits.Add(gameObject);
        enemies        = new List <Enemy>();
        spottedUnits   = new List <GameObject>();
        currentCommand = "idle";
        localUnit      = commandHub.isLocalPlayer;

        if (!isServer)
        {
            return;
        }

        InitBT();
        StartCoroutine(ShootCoroutine());
        StartCoroutine(RefreshCoroutine());
    }