private void Update() { if (paused) { //Checks if this object or its children are the last chosen objects if (FamilyLastChosen()) { selectionCircleSprite.enabled = true; //Checks if this already has a velocityChanger child if (velocityChanger == null) { velocityChanger = Instantiate(velChangerPrefab, transform); velocityChanger.transform.rotation = transform.rotation; Vector3 velocityOffset = velocity; velocityOffset.z = velocityChanger.transform.localPosition.z; velocityChanger.transform.position = transform.position + velocityOffset; } //Checks if the user has chosen to try and track or untrack an object if (Input.GetKeyDown("c")) { //If c is pressed and this object was already being tracked it will deselect itself if (trackedBody != this) { tracking = true; trackedBody = this; } else { tracking = false; trackedBody = null; } } } else { selectionCircleSprite.enabled = false; if (velocityChanger) { Destroy(velocityChanger.gameObject); velocityChanger = null; } } //Updating the stellar body's velocity based on the velocityChanger if (velocityChanger) { velocity = velocityChanger.GetVelocityVec(); } } else { //Checks if the user wants to untrack an object while the simulation is playing if (Input.GetKeyDown("c")) { tracking = false; trackedBody = null; } } }
private void GameUnpaused(object sender, EventArgs e) { selectionCircleSprite.enabled = false; paused = false; if (velocityChanger) { Destroy(velocityChanger.gameObject); velocityChanger = null; } }
void Awake() { //Setting componenets sprite = GetComponent <SpriteRenderer>(); dragAndDrop = GetComponent <DragAndDrop>(); selectionCircle = transform.GetChild(0); selectionCircleSprite = selectionCircle.GetComponent <SpriteRenderer>(); velocityChanger = null; //Giving this object a random color SetRandomColour(); //Setting up events GameEvents.eventManager.Pause += GamePaused; GameEvents.eventManager.Play += GameUnpaused; }