Question by
zamesyne · Aug 12, 2020 at 11:58 AM ·
physicsprefabprefab changing at runtime
How To Reset Prefab Values after exiting Playmode?
So what I'm doing is that I'm changing the speed of my obstacle through a Coroutine and the value of the speed changes during the Coroutine. However the value doesn't reset to its original value when exiting the PlayMode.
Please help!
The first script below is of my Obstacle.
private void Start()
{
SetSpeed(4f);
}
void Update()
{
Move();
}
void Move()
{
transform.Translate(Vector3.down * Time.deltaTime * speed);
}
public void Die()
{
GameObject Explosion = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
Destroy(gameObject);
Destroy(Explosion, 2f);
}
public void SetSpeed(float Speed)
{
speed = Speed;
}
public float GetSpeed()
{
return speed;
}
private void OnTriggerEnter2D(Collider2D collision)
{
Die();
}
The second script below is of my spawner!
public GameObject LeftSpawnerPosition;
public GameObject RightSpawnerPosition;
public GameObject MiddleSpawnerPosition;
[SerializeField] GameObject obstacle;
// config param
[SerializeField] float TimeBtwSpawn = 2f;
void Start()
{
StartCoroutine("SpawnObstacles");
}
IEnumerator SpawnObstacles()
{
while (true)
{
yield return new WaitForSeconds(TimeBtwSpawn);
int position = Random.Range(0, 3);
if (position == 0)
{
GameObject LeftObstacle = Instantiate(obstacle, LeftSpawnerPosition.transform.position, Quaternion.identity) as GameObject;
}
else if (position == 1)
{
GameObject MiddleObstacle = Instantiate(obstacle, LeftSpawnerPosition.transform.position, Quaternion.identity) as GameObject;
}
else if (position == 2)
{
GameObject RightObstacle = Instantiate(obstacle, LeftSpawnerPosition.transform.position, Quaternion.identity) as GameObject;
}
}
}
public void SetTimeBetweenSpawn(float time)
{
TimeBtwSpawn = time;
}
public float GetTimeBetweenSpawn()
{
return TimeBtwSpawn;
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I destroy my Spawned Object, if does not toach anything? 0 Answers
Build a House using code and prefabs 0 Answers
TMP text that was changed from script is overridden by the one in editor 0 Answers
Lag When Instantiating Particle System Prefab On Collision 0 Answers
How can I animate my 3D object without affecting the physics? 0 Answers