void LaunchMissile() { Transform targetPosition = GameObjectUtilts.GetNearestObjectTransformByTag(transform.position, "Turret"); if (targetPosition == null) { return; } Vector3 dir = (transform.right * ((int)direction)); dir.Normalize(); GameObject objCreatedMissile = (GameObject)Instantiate(objMissile, launcherTrans.position, Quaternion.identity); float rotZ = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.Euler(0f, 0f, rotZ - 90); objCreatedMissile.GetComponent <EnemyHomingMissileController>().Target = targetPosition.position; objCreatedMissile.GetComponent <EnemyHomingMissileController>().Direction = dir; objCreatedMissile.GetComponent <EnemyHomingMissileController>().Rotation = rotation; objCreatedMissile.GetComponent <EnemyHomingMissileController>().moveSpeed = 100.0f; }
void Start() { objCamera = (tk2dCamera)GameObject.FindWithTag("MainCamera").GetComponent <tk2dCamera>(); objPlayer = (GameObject)GameObject.FindWithTag("Player"); objScriptVariable = (VariableScript)objPlayer.GetComponent(typeof(VariableScript)); objSprite = GetComponent <tk2dSprite>(); objBarrel = GameObjectUtilts.FindChild(gameObject.name, "Barrel"); missileOrigin = objBarrel.transform.Find("BulletOrigin"); health = maxHealth; }
void Start() { //Debug.Log("MinigunController:Start(" + gameObject.name + ")"); start = Time.time; health = maxHealth; objSprite = GetComponent <tk2dSprite>(); // Get child barrel object which is what rotates and fires projectiles objBarrel = GameObjectUtilts.FindChild(gameObject.name, "Barrel"); //TODO I think the bullet origin should be stored as a Transform array so // more it does not have to be hard coded. // Get the origin for projectiles on the barrel object. // This is where projectiles shot from this gun will originate. barrelOrigin0 = objBarrel.transform.Find("BarrelOrigin0"); barrelOrigin1 = objBarrel.transform.Find("BarrelOrigin1"); // Only track objects on this layer. trackingLayer = LayerMask.NameToLayer("Enemies"); }
void DropBomb() { Transform targetPosition = GameObjectUtilts.GetNearestObjectTransformByTag(transform.position, "Turret"); if (targetPosition == null) { return; } //Vector3 dir = (transform.right * ((int)direction)); Vector3 dir = -transform.up; dir.Normalize(); GameObject objCreatedBomb = (GameObject)Instantiate(objBomb, launcherTrans.position, Quaternion.identity); float rotZ = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.Euler(0f, 0f, rotZ - 90); objCreatedBomb.GetComponent <EnemyBombController>().Direction = dir; objCreatedBomb.GetComponent <EnemyBombController>().Rotation = rotation; }