Q1) Q1) Can you explain this code? using for what? using System.Collections; using System.Collections.Generic; using UnityEngine; public class CoinSpawn : MonoBehaviour { public GameObject[] coin; public Transform spawnPoint; private float spawnTime = 10f; private float spawnNext = 20f; private float maxHeight = 3f; private float minHeight = -2f; private float timer; void Start () { timer = Time.time; } void Update () { float t = Time.time - timer; if (t >= spawnTime) { transform.position = new Vector3(spawnPoint.position.x, Random.Range(maxHeight, minHeight)); Quaternion spawnRotation = Quaternion.identity; int rand = Random.Range(0, 2); Instantiate(coin[rand], transform.position, transform.rotation); spawnTime = Time.time + spawnNext; } } }
Q1) Q1) Can you explain this code? using for what?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinSpawn : MonoBehaviour {
public GameObject[] coin;
public Transform spawnPoint;
private float spawnTime = 10f;
private float spawnNext = 20f;
private float maxHeight = 3f;
private float minHeight = -2f;
private float timer;
void Start () {
timer = Time.time;
}
void Update () {
float t = Time.time - timer;
if (t >= spawnTime) {
transform.position = new Vector3(spawnPoint.position.x, Random.Range(maxHeight, minHeight));
Quaternion spawnRotation = Quaternion.identity;
int rand = Random.Range(0, 2);
Instantiate(coin[rand], transform.position, transform.rotation);
spawnTime = Time.time + spawnNext;
}
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)