コード例 #1
0
ファイル: Tower.cs プロジェクト: dmaulikr/inkTD
    private void Timer_Elapsed(object sender, System.EventArgs e)
    {
        //Finding the target
        FindTarget();

        //Firing the projectile
        if (target != null)
        {
            Vector3               curveStart;
            Quaternion            rotation   = Quaternion.identity;
            GameObject            projectile = Instantiate(projectileObject, spawnPos, rotation) as GameObject;
            Projectile_Controller controller = projectile.GetComponent <Projectile_Controller>();
            controller.SetCreator(this);
            controller.Life   = projectileLife;
            controller.Target = target;
            controller.Damage = damage;
            // may want to apply effects like fire here to the controller

            //Computing the 'rough' estimate for the projectile's arc using the spawn position
            Vector3 curveEnd = target.GetComponent <Creature>().PredictPos(projectileLife / 1000); //target.transform.position;
            Vector3 curveMid = new Vector3((spawnPos.x + curveEnd.x) / 2, height, (spawnPos.z + curveEnd.z) / 2);
            controller.SetCurvePoints(spawnPos, curveMid, curveEnd);

            //Computing the actual projectile arc.
            curveStart = spawnPos + (projectile.transform.forward * (projectileSize.y * 0.75f));
            curveMid   = new Vector3((curveStart.x + curveEnd.x) / 2, height, (curveStart.z + curveEnd.z) / 2);
            controller.SetCurvePoints(curveStart, curveMid, curveEnd);

            VisualizeBezier(curveStart, curveMid, curveEnd);

            //Applying the particles based on the modifiers present:
            string     particleName = string.Empty;
            GameObject particle;
            foreach (Modifier m in Modifiers)
            {
                particleName = Help.GetModifierParticlePrefab(m.type);
                if (particleName != string.Empty)
                {
                    particle = Instantiate(Resources.Load("Particles/" + particleName), projectile.transform) as GameObject;
                    particle.transform.localRotation = Quaternion.Euler(-180, 0, 0);
                }
            }

            if (audioSource != null && shootSoundEffect != null)
            {
                //audioSource.PlayOneShot(shootSoundEffect, Help.TowerSoundEffectVolume);
                audioSource.PlayOneShot(shootSoundEffect);
            }
        }
    }
コード例 #2
0
ファイル: bubbleHit.cs プロジェクト: nizarrizki/MBC_GAMETECH
 // Start is called before the first frame update
 void Awake()
 {
     myPc = GetComponentInParent <Projectile_Controller>();
 }