コード例 #1
0
ファイル: Mortar.cs プロジェクト: tenvinc/TowerProgrammer
    public override void Shoot(TurretShooting turret, Transform _target)
    {
        GameObject projectile        = Instantiate(bulletPrefab, turret.firePoint.position, turret.firePoint.rotation);
        Projectile projectilePhysics = projectile.GetComponent <Projectile>();
        // the target is projected to be on the same y as projectile
        Vector3 targetInXZ     = new Vector3(_target.position.x, projectile.transform.position.y, _target.position.z);
        Vector3 projectileInXZ = new Vector3(projectile.transform.position.x, projectile.transform.position.y, projectile.transform.position.z);

        projectile.transform.LookAt(targetInXZ);

        // shorthand for formula https://vilbeyli.github.io/Projectile-Motion-Tutorial-for-Arrows-and-Missiles-in-Unity3D/#targetlocations
        float   R           = Vector3.Distance(projectileInXZ, targetInXZ);
        float   G           = -projectilePhysics._gravity;
        Vector3 firePointXZ = new Vector3(turret.firePoint.position.x, 0f, turret.firePoint.position.z);
        Vector3 refPointXZ  = new Vector3(turret.refPoint.position.x, 0f, turret.refPoint.position.z);
        float   tanAlpha    = (turret.firePoint.position.y - turret.refPoint.position.y) / Vector3.Distance(firePointXZ, refPointXZ);
        float   H           = _target.position.y - projectile.transform.position.y;

        // calculate the local space components of the velocity
        // required to land the projectile on the target object
        float Vz = Mathf.Sqrt(G * R * R / (2.0f * (H - R * tanAlpha)));
        float Vy = tanAlpha * Vz;

        // create the velocity vector in local space and get it in global space
        Vector3 localVelocity  = new Vector3(0f, Vy, Vz);
        Vector3 globalVelocity = projectile.transform.TransformDirection(localVelocity);

        projectilePhysics.Initialise(globalVelocity);
    }
コード例 #2
0
    public void Shoot()
    {
        if (Shooting == null)
        {
            Shooting = GetComponentInParent <TurretShooting>();
        }

        Shooting.Fire();
    }
コード例 #3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        turret = collision.gameObject.GetComponent <TurretShooting>();

        if (turret != null && !turret.RetState())
        {
            enemy.enabled = false;
            turret.Disabled();
            worked      = true;
            source.clip = sound;
            source.Play();
        }
    }
コード例 #4
0
ファイル: Regular.cs プロジェクト: tenvinc/TowerProgrammer
    public override void Shoot(TurretShooting turret, Transform _target)
    {
        AudioClip   choice      = sfxSelection.PlayWeightedSelection();
        AudioSource turretAudio = turret.GetComponent <AudioSource>();

        turretAudio.clip = choice;
        if (choice != null)
        {
            turretAudio.Play();
        }
        turret.muzzleFX.Play();
        Transform firePoint = turret.firePoint;
        // GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        GameObject bullet = ObjectPool.instance.GetPooledObject(0);

        if (bullet == null)
        {
            return;
        }
        bullet.transform.position = firePoint.position;
        bullet.transform.rotation = firePoint.rotation;
        bullet.SetActive(true);
        bullet.GetComponent <Bullet>().SetTarget(_target);
    }
コード例 #5
0
	TurretShooting turretShooting;						//Reference to the TurretShooting script on the barrel of the gun

	void Start()
	{
		audioSource = GetComponent<AudioSource>();
		turretShooting = GetComponentInChildren<TurretShooting> ();
	}
コード例 #6
0
ファイル: TurretAI.cs プロジェクト: Python958/CPT_Capstone
 // Use this for initialization
 void Start()
 {
     m_tracker = GetComponent <TurretTracker>();
     m_shooter = GetComponent <TurretShooting>();
     m_range   = GetComponent <RangeChecker>();
 }
コード例 #7
0
    public void SoftResetLevel()
    {
        spawner.ResetWaveNum(); // Reset Wave Num to 0
        List <GameObject> enemiesInScene = new List <GameObject>();

        // Destroying enemies currently in the scene
        for (int i = 0; i < tagmasterso.Tags.Count; i++)
        {
            string       currTag = tagmasterso.Tags[i];
            GameObject[] temp    = GameObject.FindGameObjectsWithTag(currTag);
            for (int j = 0; j < temp.Length; j++)
            {
                enemiesInScene.Add(temp[j]);
            }
        }
        for (int i = 0; i < enemiesInScene.Count; i++)
        {
            Destroy(enemiesInScene[i]);
        }
        // Resetting debuff status of every tower
        for (int i = 0; i < tagmasterso.towerTags.Count; i++)
        {
            string       currTag = tagmasterso.towerTags[i];
            GameObject[] temp    = GameObject.FindGameObjectsWithTag(currTag);
            for (int j = 0; j < temp.Length; j++)
            {
                TurretShooting turret = temp[j].GetComponent <TurretShooting>();
                if (turret != null)
                {
                    turret.resetDebuff();
                    turret.ResetBlind();
                }
            }
        }
        // Reset gold
        PlayerStats.Money      -= PlayerStats.moneyEarned;
        PlayerStats.moneyEarned = 0;
        // Reset health
        PlayerStats.Lives    += PlayerStats.livesLost;
        PlayerStats.livesLost = 0;
        // Reset currCount
        currCount = 0;
        // Reset monstersKilled
        PlayerStats.monstersKilled = 0;
        // Reenable the ui
        InterfaceManager.ui.ResetStage();
        // Reset the game complete, game ended, game complete ui, game ended ui
        gameEnded      = false;
        stageCompleted = false;
        gameOverUI.SetActive(false);
        StageCompleteUI.SetActive(false);
        // Reset the status of the pause button/ resume button
        InterfaceManager.ui.PauseText.SetActive(true);
        InterfaceManager.ui.ResumeText.SetActive(false);
        // Reset bezier lines

        /*
         * for (int i = 0; i < Waypoints.waypoints.Length - 1; i++)
         * {
         *  GameObject line = ObjectPool.instance.GetPooledObject(1);
         *  if (line == null)
         *  {
         *      return;
         *  }
         *  line.GetComponent<Bezier>().point0 = Waypoints.waypoints[i];
         *  line.GetComponent<Bezier>().point1 = Waypoints.waypoints[i + 1];
         *  line.SetActive(true);
         * }
         */
        MainPlayerStats.instance.ReadData();
    }
コード例 #8
0
 public abstract void Shoot(TurretShooting turret, Transform target);