In: Computer Science
View the following C# Script carefully. Assume that the Script
is enabled, is attached to an active GameObject, and addresses the
appropriate namespaces first. Discuss when and how often during the
game the Update() function will be executed. Discuss each line
(from line 9 to 17, excluding the lines with curly brackets) to
detail what the code inside the update function is doing. Be sure
to outline how the variables are being used during your discussion.
1 public class Player : MonoBehaviour 2 { 3 public GameObject
coinPrefab; 4 private GameObject coin; 5 public Transform
spawnpoint; 6 7 void Update() 8 { 9 if
(Input.GetMouseButtonDown(0)) 10 { 11 Instantiate(coinPrefab,
spawnpoint.position, spawnpoint.rotation); 12 } 13 if
(Input.GetMouseButtonDown(1)) 14 { 15 coin =
GameObject.FindWithTag("Coin"); 16 Destroy(coin); 17 } 18 } 19
}
code:-
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using someNamespace;
1 public class Player : MonoBehaviour
2 {
3 public GameObject coinPrefab;
4 private GameObject coin;
5 public Transform spawnpoint;
6
7 void Update()
8 {
9 if
(Input.GetMouseButtonDown(0))
10 {
11 Instantiate(coinPrefab,
spawnpoint.position, spawnpoint.rotation);
12 }
13 if
(Input.GetMouseButtonDown(1))
14 {
15 coin
= GameObject.FindWithTag("Coin");
16 Destroy(coin);
17 }
18 }
19 }