I have 3 classes:
UnitSpawn.cs
public class UnitSpawn : MonoBehaviour
{
private GameObject position;
private Button button;
public void Awake()
{
button = GameObject.Find("Canvas/Button").GetComponent<Button>();
}
public void SpawnUnit(Unit unit)
{
position = GameObject.Find(unit.SpawnPosition);
Instantiate(unit.gameObject, position.transform.position,
position.transform.rotation);
button.enabled = false;
StartCoroutine(WaitTime(unit.TimeBetweenSpawns));
}
IEnumerator WaitTime(int timeBetweenSpawns)
{
yield return new WaitForSeconds(timeBetweenSpawns);
button.enabled = true;
}
}
Unit.cs
public abstract class Unit : MonoBehaviour
{
public abstract string SpawnPosition { get; set; }
public abstract int MovementSpeed { get; set; }
public abstract int TimeBetweenSpawns { get; set; }
public abstract int Health { get; set; }
public abstract int AttackSpeed { get; set; }
public abstract int Damage { get; set; }
public void Move()
{
var rb = GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(-MovementSpeed, rb.velocity.y);
}
}
Unit1.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Unit1 : Unit
{
public override string SpawnPosition { get; set; } =
"SpawnManager/SpawnPositionForUnit1";
public override int MovementSpeed { get; set; } = 3 ;
public override int TimeBetweenSpawns { get; set; } = 3;
public override int Health { get; set; }
public override int AttackSpeed { get; set; }
public override int Damage { get; set; }
public void Update()
{
Move();
}
}
When I change values for some properties they don’t applied even after I pressing play in Unity or after I rebuild project in VS. Then, in some magic way, maybe when I reboot my PC they get applied. Something wrong with this. Why does it happens? (sorry for my bad english)