I’m still a bit confused on the proper (or most efficient) ways for components to communicate with each other.
Here’s the code I have to make the mouse input available globally:
using UnityEngine;
using Sytem.Collections;
public class InputManager : MonoBehavior {
public static float mouseInputX;
Public static float mouseInputY;
Public static float mouseInputWheel;
void Update(){
mouseInputY = Input.GetAxisRaw("Vertical");
mouseInputX = Input.GetAxisRaw("Horizontal");
mouseInputWheel = Input.GetAxisRaw("Mouse ScrollWheel");
}
And here’s the code I’m using to access the variables from the update method of another script::
inputX = InputManager.mouseInputX;
inputY = InputManager.mouseInputY;
inputWheel = InputManager.mouseInputWheel;
I’m also using the following to make the script public, but only using that since it was in one of the examples, and it seemed to work. Have no clue how to use it otherwise.
using UnityEngine;
using System.Collections;
public enum ThrowGameState { inert, swing, release, spin, aim, end };
public class ThrowBall2 : MonoBehavior {
public static ThrowBall2 CS;
public ThrowGameState gameState;
void Awake()
{
CS = this;
gameState = ThrowGameState.inert;
}
And I reference methods inside this way:
ThrowBall2.CS.ScoreKeeper();
state = ThrowBall2.CS.gameState;
That has been very useful setting and evaluating based on the gameState. But I don’t really understand its anatomy etc, which keeps me from taking full advantage of its capabilities.
So if someone could help me with best practices , other options etc, that would be wonderful! Thanks ahead of time!
P-