Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Intro_Scritping/ShipShooter/Assets/Scripts/Enemy2.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (43 sloc)
1.62 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Enemy2 : MonoBehaviour { | |
public int health = 2; | |
public GameObject wheels; | |
public Vector3 enemyAngle = new Vector3(0, 270, 90); | |
public GameObject turret; | |
public GameObject bullet; | |
public Vector3 posCanon; | |
public float test; | |
public int testInt; | |
public GameObject newBullet; | |
public Vector3 playerPos; | |
public GameObject player; | |
void OnCollisionEnter(Collision collision) | |
{ | |
if (collision.gameObject.tag == "Bullet") | |
{ | |
health = health - 1; | |
} | |
} | |
void Update() | |
{ | |
playerPos = new Vector3(player.transform.position.x, player.transform.position.y - 30, player.transform.position.z); | |
//Shooting =================================================== | |
posCanon = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f, gameObject.transform.position.z); | |
test = gameObject.transform.position.y; | |
testInt = Mathf.RoundToInt(test); | |
//shooting--------------------------------------------------------------------------------- | |
if (testInt % 4 == 0) | |
{ | |
newBullet = (GameObject)Instantiate(bullet, posCanon, transform.rotation); | |
iTween.MoveTo(newBullet, playerPos, 1); | |
} | |
//Health----------------------------------------------------------------------------------- | |
if (health == 0) | |
Destroy(gameObject); | |
if (health == 1) | |
Destroy(wheels); | |
if (transform.eulerAngles != enemyAngle) | |
transform.eulerAngles = enemyAngle; | |
} | |
} |