Need Help With Highschool Unity Game Design Project
Everything is 3D here.
Hello, so, um... I am in 10th grade and my game design course requires me to use Unity and C#. I have a project (that is currently overdue) that I am trying to figure out that tries to have me figure out code that I haven't figured out yet. It is trying to make me create a mini-game. I already have enemies and a character for the main level.
PlayerHandler:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHandler : MonoBehaviour {
private Rigidbody rb;
private float moveSpeed;
private float jumpForce;
private bool justJumped;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
moveSpeed = 400f;
jumpForce = 550f;
justJumped = false;
//Debug.Log("Hello World");
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetAxis("Horizontal") != 0){
rb.AddForce(new Vector3(moveSpeed, 0, 0) * Input.GetAxis("Horizontal"));
}
if (Input.GetButtonDown("Jump")){
if(justJumped == false){
rb.AddForce(new Vector3(0, jumpForce * Random.Range(0.8f, 1.3f), 0));
justJumped = true;
}
}
}
void OnCollisionEnter(Collision collision)
{
justJumped = false;
}
}
EnemyHandler:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHandler : MonoBehaviour {
bool goRight;
float speed;
float interval;
float lastSwitchTime;
// Use this for initialization
void Start () {
goRight = false;
speed= 1.5f;
interval = 2f;
lastSwitchTime = 0f;
}
// Update is called once per frame
void Update () {
if (goRight == true)
{
transform.Translate(speed * Time.deltaTime, 0, 0);
}
else
{
transform.Translate(speed *-1 *Time.deltaTime, 0, 0);
}
if(Time.time > lastSwitchTime + interval)
{
lastSwitchTime = Time.time;
if (goRight == true)
{
goRight = false;
}
else
{
goRight=true;
}
}
}
}
I just put that code in there so maybe you can base something for the spaceship and flying enemy? Maybe?
I need to get this done or else I can't continue on with the course. That code is from an activity from a previous lesson, which had me learn how to write code. I have no clue what I'm supposed to do.
The minigame involves controlling a spaceship (called MinGameShip). The enemy is called FlyEnemy. So, therefore, I will need two scripts. One being called MinGameShipHandler and the other being called FlyEnemyHandler. Both MinGameShip and FlyEnemy were built by me in-engine. I clicked "GameObject" a lot. Don't worry. I precreated prefabs for them. Then I inserted every game object into a base via hierarchy view, and then simply dragged and dropped the hierarchical structure into their respective prefabs.
I have an idea for the ship. It turns towards where the mouse cursor is. If the W key or up arrow key is pressed, it toward the cursor. If S key or down arrow is press, it moves away from cursor. If the a and d keys or left and right arrow keys, it strafes side to side. Movement across the z -axis is constrained. MinGameShip can also shoot bullets back at FlyEnemy,
I also need help with programming the camera to follow MinGameShip in the minigame, as well as Player in the main game.
Also, I want FlyEnemy to fly, but constrained to movement across the x and y axis, be able to fire bullets at MinGameShip, and only chase MinGameShip only when MinGameShip is within a certain radius of FlyEnemy. Otherwise, it's just in random patrol mode.
Remember: movement for both MinGameShip and FlyEnemy are constrained to the x and y axis. It can't move across the z axis.
Can you help, please? I am getting stressed trying to figure this out on my own and I'm already behind.