Exemplo n.º 1
0
	/// <summary>
	/// Shoot this cannon
	/// </summary>
	/// <param name="shotColor"> The color to be shot </param>
	public void Shoot(Color shotColor) {

		if(fShootTimer < fProjectileInterval)
			return;

		fShootTimer = 0.0f;

		// Create an instance of the projectile
		if(projectilePrefab==null)
			return;

		Quaternion qRotation = Quaternion.identity;
		qRotation = trCannon.rotation * Quaternion.Euler(-90,0,0);

		// Create the bullet
		Vector3 v3ShotStartPosition = ((trShotOrigin == null) ? trCannon.position : trShotOrigin.position);
		GameObject goProjectile = Spawner.Spawn(projectilePrefab, v3ShotStartPosition, qRotation) as GameObject;

		if(goProjectile == null) {

			// DEBUG
			Debug.LogError(this.transform + " Couldn't instantiate the projectile " + projectilePrefab);
		}

		// Set the projectile color
		CBaseProjectile scriptProjectile = goProjectile.GetComponent<CBaseProjectile>();
		scriptProjectile.Setup(this.transform, shotColor);
	}
Exemplo n.º 2
0
    /// <summary>
    /// Shoot the enemy. It works on a timer
    /// </summary>
    void DoShooting()
    {
        if (fShootTimer > 0)
        {
            return;
        }

        // Resets the timer
        fShootTimer = fTimeToShootAgain + UnityEngine.Random.Range(-0.2f, 2.0f);

        Quaternion qRotation    = Quaternion.LookRotation(v3TargetPosition - trMesh.transform.position, Vector3.forward);
        GameObject goProjectile = Spawner.Spawn(projectilePrefab, trMesh.transform.position, qRotation) as GameObject;

        // Set the projectile color
        CBaseProjectile scriptProjectile = goProjectile.GetComponent <CBaseProjectile>();

        scriptProjectile.Setup(this.transform, myColor);
    }