Space X Rocket Test

My pretend space X rocket test.
Note the game played differently under the editor than it did under the built game!

Blockquote
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rocket_Guidance : MonoBehaviour
{
// Start is called before the first frame update

Rigidbody rb;
AudioSource audio;
void Start()
{
    rb = GetComponent<Rigidbody>();

    audio = GetComponent<AudioSource>();
}

// Update is called once per frame
void Update()
{
    ProcessInput();
}

private void Rotate()
{
    const int rot_step = 30;
    int rot = 0;
    Vector3 v;

    //LEFT PRESSED

    rb.freezeRotation = true;

    if (Input.GetKey(KeyCode.A))
    {
        rot += rot_step;
        print("Rotating Left");
    }

    if (Input.GetKey(KeyCode.D))
    {
        rot -= rot_step;
        print("Rotating Right");
    }

    transform.Rotate(Vector3.forward * rot * Time.deltaTime);
    rb.freezeRotation = false;
}

private void Thrust()
{



    //SPACE PRSSED
    if (Input.GetKey(KeyCode.Space))
    {
        //print("Thrusting");
        rb.AddRelativeForce(Vector3.up);
        if (!audio.isPlaying)
        {
            audio.Play();
        }
    }
    else
    {
        if (audio.isPlaying)
        {
            audio.Stop();
        }
    }
}

void ProcessInput()
{
    Thrust();
    Rotate();
}

}

Blockquote

1 Like

I love it! I am excited with what the launch coming up!

Privacy & Terms