Hi guys,
Want my hyperdrive to kick in on my space ship whenever the hyperdrive bool is true. It runs the process once perfectly, and unchecks true when its finished but clicking true again in the inspector doesnt start the process again. Or is there a better way of repeating function calls? I’m sure im doing something stupid that im just not seeing. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HyperDrive : MonoBehaviour
{
public bool hyperspaceJump = false;
private bool calloutCompleted = false;
private bool speedUpStarSpeed = false;
private bool slowDownStarSpeed = false;
public AudioSource hyperdriveAnnouncement;
public AudioSource hyperDriveSound;
public ParticleSystem ps;
void Update()
{
InitHyperspace();
SpeedUpStars();
SlowDownStars();
}
void InitHyperspace()
{
if (hyperspaceJump)
{
Invoke("StartHyperAnnouncement", 3);
}
}
void SpeedUpStars()
{
if (speedUpStarSpeed)
{
ps.startSpeed += 0.9f;
ps.startSize += 0.06f;
}
}
void SlowDownStars()
{
if (slowDownStarSpeed)
{
ps.startSpeed = 10f;
ps.startSize = 0.7f;
}
}
void StartHyperAnnouncement()
{
if (!calloutCompleted)
{
hyperdriveAnnouncement.Play();
calloutCompleted = true;
StartCoroutine(StartHyperdriveSequence());
}
}
IEnumerator StartHyperdriveSequence()
{
float waiting = 2;
yield return new WaitForSeconds(waiting);
hyperDriveSound.Play();
speedUpStarSpeed = true;
StartCoroutine(EndHyperdriveSequence());
}
IEnumerator EndHyperdriveSequence()
{
float waiting = 8;
yield return new WaitForSeconds(waiting);
speedUpStarSpeed = false;
slowDownStarSpeed = true;
hyperspaceJump = false;
}
}