using System.Collections; using System.Collections.Generic; using UnityEngine; ///…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
/// /// Spawns spawnCount (e.g., 40) objects within the Random.Range(-spawnRange, spawnRange) /// and sets their localScale to Vector3.one * Random.Range(scaleMin, scaleMax). /// You can also add a random Y rotation if you want, so they aren't all oriented the /// same way. /// Note that this is attached to the same GameObject multiple times! /// public class SpawnWorldObjects : MonoBehaviour { [Header("Inscribed")] [Tooltip("The number of these objects to spawn")] public int spawnCount = 40; [Tooltip( "The maximum x, y, & z position for spawned GameObjects" )] public Vector3 spawnRangeMax = new Vector3( 512, 0, 512 ); [Tooltip( "The minimum x, y, & z position for spawned GameObjects" )] public Vector3 spawnRangeMin = new Vector3( -512, 0, -512 ); [Tooltip( "The maximum uniform localScale for spawned GameObjects" )] public float scaleMax = 80; [Tooltip("The minimum uniform localScale for spawned GameObjects")] public float scaleMin = 20; [Tooltip( "The List of prefabs that can be spawned by this script" )] public List prefabs;
// Start is called before the first frame update void Start() { // for i from =0 to <spawnCount for ( i = 0; i <spawnCount; i++) { // Instantiate a random GameObject gObj from the prefabs List // Set x, y, and z values of a Vector3 pos from spawnRange values // Set the position of gObj to pos // Set the localScale of gObj to be betweeb scaleMin and scaleMax } }} Fill out the code for the comments under the start function in this script
- Assistant
void Start() { for (int i = 0; i < spawnCount; i++) { // Instantiate a random GameObject gObj from the prefabs List GameObject gObj = Instantiate(prefabs[Random.Range(0, prefabs.Count)]);
// Set x, y, and z values of a Vector3 pos from spawnRange values float x = Random.Range(spawnRangeMin.x, spawnRangeMax.x); float y = Random.Range(spawnRangeMin.y, spawnRangeMax.y); float z = Random.Range(spawnRangeMin.z, spawnRangeMax.z); Vector3 pos = new Vector3(x, y, z); // Set the position of gObj to pos gObj.transform.position = pos; // Set the localScale of gObj to be between scaleMin and scaleMax float scale = Random.Range(scaleMin, scaleMax); gObj.transform.localScale = Vector3.one * scale; }}
- User
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
/// /// Reloads the entire scene whenever the plane collides with anything /// [DisallowMultipleComponent] public class ReloadOnCollision : MonoBehaviour { private void OnCollisionEnter(Collision collision) { // Reload Scene 0
}} Fill out the code for the comment under the OnCollisionEnter function of this script
- Assistant
private void OnCollisionEnter(Collision collision) { // Reload Scene 0 SceneManager.LoadScene(0); }
- User
- Assistant
using System.Collections; using System.Collections.Generic; using UnityEngine;
[DisallowMultipleComponent] public class PlaneControls : MonoBehaviour { static public float BOOST_RECHARGE_U { get; private set; }
[Header("Inscribed")] public Transform model; public float baseSpeed = 40; public float boostSpeed = 200; public float boostDuration = 1; public float boostRecharge = 10; public float rotVel = 40; public float rollMax = -60; public float yVelMax = 20; public float yVelMin = -5; public float yVelGravity = -8; [Header("Dynamic")] public float speed = 40; public float yVel = 0; public float lastBoostTime = -10; Rigidbody rigid; void Start() { speed = baseSpeed; rigid = GetComponent<Rigidbody>(); rigid.velocity = transform.forward * speed; } private void Update() { if (BOOST_RECHARGE_U == 1 && Input.GetKeyDown(KeyCode.Space)) { speed = boostSpeed; lastBoostTime = Time.time; } } void FixedUpdate() { float horizontalInput = Input.GetAxis("Horizontal"); float boostU = Mathf.Clamp01((Time.time - lastBoostTime) / boostDuration); speed = (1 - boostU) * boostSpeed + boostU * baseSpeed; BOOST_RECHARGE_U = Mathf.Clamp01((Time.time - lastBoostTime) / boostRecharge); float rotationAmount = horizontalInput * rotVel * Time.fixedDeltaTime; transform.Rotate(Vector3.up, rotationAmount); float roll = horizontalInput * rollMax; model.localRotation = Quaternion.Euler(0, 0, roll); yVel += yVelGravity * Time.fixedDeltaTime; yVel = Mathf.Clamp(yVel, yVelMin, yVelMax); rigid.velocity = transform.forward * speed + yVel * Vector3.up; } void OnTriggerStay(Collider other) { if (other.GetComponentInParent<Updraft>() != null) { yVel = yVelMax; } } - User
- Assistant
void FixedUpdate() { float horizontalInput = Input.GetAxis("Horizontal"); float boostU = Mathf.Clamp01((Time.time - lastBoostTime) / boostDuration); speed = (1 - boostU) * boostSpeed + boostU * baseSpeed; BOOST_RECHARGE_U = Mathf.Clamp01((Time.time - lastBoostTime) / boostRecharge);
float rotationAmount = horizontalInput * rotVel * Time.fixedDeltaTime; transform.Rotate(Vector3.up, rotationAmount); float roll = horizontalInput * rollMax; model.localRotation = Quaternion.Euler(0, 0, roll); yVel += yVelGravity * Time.fixedDeltaTime; yVel = Mathf.Clamp(yVel, yVelMin, yVelMax); rigid.velocity = transform.forward * speed + yVel * Vector3.up;}
- User
// Set speed based on (1 - boostU) * boostSpeed + boostU * baseSpeed
// BOOST_RECHARGE_U varies from 0 to 1 based on time since lastBoostTime // divided by boostRecharge. Clamp it so that it doesn’t go above 1.
// Multiply the Horizontal axis value by rotVel and fixedDeltaTime to get // the amount of rotation around y to apply via transform.Rotate this FixedUpdate()
// Apply that rotation around y (the “pan” axis that rotates left and right) // by calling transform.Rotate()
// Set model.localRotation to roll (i.e., bank) the model of the plane left & right // as the plane turns. The “roll” axis is the local z axis of the Transform named model. // The roll value should be Horizontal axis * rollMax
// Add yVelGravity * fixedDeltaTime to yVel (yVelGravity is negative)
// Clamp yVel so that it stays between yVelMin and yVelMax
// Set rigid.velocity to (transform.forward times speed) plus (yVel times Vector3.up) Why were these comments not filled out?
- Assistant
I apologize for the oversight. Here is the completed code for these comments:
void FixedUpdate() { float horizontalInput = Input.GetAxis("Horizontal"); float boostU = Mathf.Clamp01((Time.time - lastBoostTime) / boostDuration); speed = (1 - boostU) * boostSpeed + boostU * baseSpeed; BOOST_RECHARGE_U = Mathf.Clamp01((Time.time - lastBoostTime) / boostRecharge); float rotationAmount = horizontalInput * rotVel * Time.fixedDeltaTime; transform.Rotate(Vector3.up, rotationAmount); float roll = horizontalInput * rollMax; model.localRotation = Quaternion.Euler(0, 0, roll); yVel += yVelGravity * Time.fixedDeltaTime; yVel = Mathf.Clamp(yVel, yVelMin, yVelMax); rigid.velocity = transform.forward * speed + yVel * Vector3.up; }Apologies again for the oversight.