Dudes of 708's knowledge base for getting started and tools we use
Back to homepage • software resources guide • Unity setup guide
This is just how some of us learned how to use Unity. Your use case may be different.
GhostManager.cs
in Footnote 1.I’m getting a Unity package manager error with options Retry, Quit, and Continue! It mentions editing my package.json
file and an error while resolving packages.
This is an internet connection issue with Unity’s analytics package. Go to your project folder’s Packages folder, and open
package.json
. Inside, find the line that sayscom.unity.analytics
and delete it. Restart Unity, and you should be able to open the project now.
Here is the source code of GhostManager.cs
:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct GhostTransform {
public Vector3 position;
public Quaternion rotation;
public GhostTransform(Transform transform) {
this.position = transform.position;
this.rotation = transform.rotation;
}
}
public class GhostManager : MonoBehaviour {
public Transform kart;
public Transform ghostKart;
public bool recording;
public bool playing;
public List<GhostTransform> recordedGhostTransforms = new List<GhostTransform>();
private GhostTransform lastRecordedGhostTransform;
void Start() {}
void Update() {
if (recording == true) {
if (kart.position != lastRecordedGhostTransform.position || kart.rotation != lastRecordedGhostTransform.rotation) {
var = newGhostTransform = new GhostTransform(kart);
recordedGhostTransforms.Add(newGhostTransform);
lastRecordedGhostTransform = newGhostTransform;
}
}
if (playing == true) { Play(); }
}
void Play() {
ghostKart.gameObject.SetActive(true);
StartCoroutine(StartGhost());
playing = false;
}
IEnumerator StartGhost() {
for (int i = 0; i < recordedGhostTransforms.Count; i++) {
ghostKart.position = recordedGhostTransforms[i].position;
ghostKart.rotation = recordedGhostTransforms[i].rotation;
yield return new WaitForFixedUpdate();
}
}
}
Here’s how to install ProGrids, a plugin for Unity: