Thanks for the reply! I mean hitting the stop button within the Unity Editor. And yeah, weirdly enough, it changes the int that’s in the prefab. Whenever I terminate and restart, the public score int on the prefab stays permanently changed.
Here’s my player control script:
public class ShipControls : MonoBehaviour {
public Transform bullet;
public Transform startPos;
public Transform explode;
public Transform enemyBullet;
public Transform boss;
public Transform spawnPoint;
public int moveSpeed = 5;
public int lives;
public int score;
public GUIText lifeCount;
public bool canMoveLeft = true;
public bool canMoveRight = true;
public bool canMoveUp = true;
public bool canMoveDown = true;
void Start () {
Instantiate (startPos, transform.position, transform.rotation);
score = 0;
}
void Update () {
InputControl();
//Vector3 bossSpawn = spawnPoint.position;
//if (score == 21) {
// Instantiate (boss, bossSpawn, transform.rotation);
//}
}
void InputControl() {
if (Input.GetKeyDown(KeyCode.Space)) {
Instantiate (bullet, transform.position, transform.rotation);
//Shoot();
}
Vector3 moveVec = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if ((moveVec.x > 0 !canMoveRight) || (moveVec.x < 0 !canMoveLeft)) {
moveVec.x = 0;
}
if ((moveVec.z > 0 !canMoveUp) || (moveVec.z < 0 !canMoveDown)) {
moveVec.z = 0;
}
transform.Translate(moveSpeed * moveVec * Time.deltaTime);
}
void OnTriggerEnter (Collider other) {
if (other.tag == "enemyBullet") {
if (lives < 1) {
Destroy (this.gameObject);
} else {
lives -= 1;
Instantiate (explode, transform.position, transform.rotation);
transform.position = startPos.position;
}
}
}
}
And here is my enemy script:
public class InvaderScript : MonoBehaviour {
public Transform Bullet;
public Transform shipExplotion;
public Transform myBullet;
public GameObject playerobj;
private float Counter;
public float moveTimer;
public bool movingRight;
public bool movingLeft;
// Use this for initialization
void Start () {
Counter = Random.Range (0f, 5.0f);
moveTimer = 10;
}
// Update is called once per frame
void Update () {
moveTimer -= Time.deltaTime;
if (moveTimer > 5) {
movingRight = true;
} else {
movingRight = false;
}
if (moveTimer < 5) {
movingLeft = true;
} else {
movingLeft = false;
}
if (movingRight == true) {
transform.Translate (-0.1f, 0, 0);
}
if (movingRight == false) {
transform.Translate (0, 0, 0);
}
if (movingLeft == true) {
transform.Translate (0.1f, 0, 0);
}
if (movingLeft == false) {
transform.Translate (0, 0, 0);
}
if (Counter < 0) {
Counter = Random.Range (1.0f, 10.0f);
} else {
Counter -= Time.deltaTime;
}
//print (Counter);
if (moveTimer < 0) {
moveTimer = 10;
}
if (Counter < 0f) {
Instantiate (myBullet, transform.position, transform.rotation);
}
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Bullet") {
playerobj.GetComponent<ShipControls>().score += 1;
print (playerobj.GetComponent<ShipControls>().score);
Instantiate (shipExplotion, transform.position, transform.rotation);
Destroy (this.gameObject);
}
}
}
Now, I’m telling the enemy to update the ShipControls script before destroying itself, but as said, it changes the prefab permanently and not the scene instance until after I’ve terminated the game. Super frustrating as I feel like I’ve set it up properly… Also, despite my Score = 0 on void start, the score just stays the same from when I terminated last.