Hello ladies and gentlemen,
I’m learning basic movement scripts and work on getting my feet wet a bit at the moment, and now I encountered a problem I can not solve on my own. Would you help me out?
Both scripts are attached to the same gameObject (Cube). However, I want to outsource the many different methods and proccessing tasks to other scripts and make my core-script as clean as possible. The movement script works perfectly fine when I put it on Update(), but when i put it into another script and try to access it from my core-script, it doesn’t work. doesn’t put out an error, but just pauses the game. Here is my work:
Movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public void checkMovement(float speed)
{
float GetAxisHor = Input.GetAxis("Horizontal");
float GetAxisVer = Input.GetAxis("Vertical");
if (Input.GetButtonDown("Jump"))
{
transform.Translate(0, 2, 0);
}
if (GetAxisHor != 0)
{
transform.Translate((GetAxisHor * speed) * Time.deltaTime, 0, 0);
}
if (GetAxisVer != 0)
{
transform.Translate(0, 0, (GetAxisVer * speed) * Time.deltaTime);
}
}
}
Core
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeCore : MonoBehaviour {
Movement Movement;
float GetAxisHor = Input.GetAxis("Horizontal");
float GetAxisVer = Input.GetAxis("Vertical");
void Update () {
Movement.checkMovement(1f);
}
}