Properties does not have new values
Hello! I have properties in my scripts and when I was changing MovementSpeed property (while working on movement) it's all changed just fine. But when I start changing other values they have no new values. And then, when I changed Movement speed again, it's does not have new value too. Don't know what is wrong. I changed nothing in editor or code before it's happened. Hope you can help me. Here my 3 scripts and screenshot from debugger:
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();
}
}
And screenshot from the debugger:
Your answer
Follow this Question
Related Questions
Is there a cleaner way to set all the properties when declaring a new object? 2 Answers
C# property with private set method still marked as CanWrite 0 Answers
Setting another script's property from code doesn't actually set the property 1 Answer
Modular property/interaction system 1 Answer
Can someone explain this to me? Player myPlayer = new Player(); 1 Answer