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;         }     } }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 23SA
icon
Related questions
Question

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;
        }
    }
}

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning