Im new to Unity and creating a small flying game, but when I added my disabling of movement to collision, but now none of the code in my movement script works. I attached all the code that I think might be useful.
PlayerMovement
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float horizontalInput;
public float verticalInput;
public float speed = 25f;
float forwardBoost = 1f;
public bool test = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalRotate = 0f;
if (Input.GetKey(KeyCode.Q)){
horizontalRotate = 1f;
}
if (Input.GetKey(KeyCode.E)){
horizontalRotate = -1f;
}if(Input.GetKey(KeyCode.Space)){
test = true;
} if(Input.GetKeyUp(KeyCode.Space)){
test = false;
}
if(test){
forwardBoost=25f;
} else {
forwardBoost = 1f;
}
horizontalInput = Input.GetAxis("Horizontal");
verticalInput = Input.GetAxis("Vertical");
transform.Translate(speed * forwardBoost * Time.deltaTime * Vector3.forward);
transform.Rotate(speed * horizontalInput * Time.deltaTime * Vector3.up);
transform.Rotate(speed * verticalInput * Time.deltaTime * Vector3.right);
transform.Rotate(speed * 2 * horizontalRotate * Time.deltaTime * Vector3.forward);
}
}
EnemyTowardsPlayer (moves enemy towards the player, call game end method
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float horizontalInput;
public float verticalInput;
public float speed = 25f;
float forwardBoost = 1f;
public bool test = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalRotate = 0f;
if (Input.GetKey(KeyCode.Q)){
horizontalRotate = 1f;
}
if (Input.GetKey(KeyCode.E)){
horizontalRotate = -1f;
}if(Input.GetKey(KeyCode.Space)){
test = true;
} if(Input.GetKeyUp(KeyCode.Space)){
test = false;
}
if(test){
forwardBoost=25f;
} else {
forwardBoost = 1f;
}
horizontalInput = Input.GetAxis("Horizontal");
verticalInput = Input.GetAxis("Vertical");
transform.Translate(speed * forwardBoost * Time.deltaTime * Vector3.forward);
transform.Rotate(speed * horizontalInput * Time.deltaTime * Vector3.up);
transform.Rotate(speed * verticalInput * Time.deltaTime * Vector3.right);
transform.Rotate(speed * 2 * horizontalRotate * Time.deltaTime * Vector3.forward);
}
}
The GameManager only has the EndGame, which just brings you back to the main menu via the buildIndex-1;
FireBlaster
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireBlaster : MonoBehaviour
{
public GameObject blaster;
public GameObject fireObject;
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0)){
GameObject fireObjectInstance = Instantiate(fireObject, blaster.transform.position, blaster.transform.rotation);
}
}
}
Ive made sure that the keycodes and axes are connected, as well as make the axes public to see their input. They both stay at 0, meaning there is no input. I also know that it is directly affecting the PlayerMovement script as FireBlaster, which also takes Input from an axes, works.
Anyone able to figure this out?