How do I add two different values from a script on seperate game objects?
My goal is to be able to place engine prefabs onto a ship (Complete) but have their power added together to influence how fast the ship can move. So far the engines just cancel each other out and I can't find any questions related to this problem. I'm trying to add values together from the same script, is this even possible?
Here is the code that i've been using for both the movement script and the engine power script, one object seems to cancel out the other.
public class AltMove : MonoBehaviour
{
public float moveSpeed = 0f;
public Texture2D cursorTexture;
public CursorMode cursorMode = CursorMode.Auto;
public Vector2 hotSpot = Vector2.zero;
// Use this for initialization
void Start()
{
Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
}
// Update is called once per frame
void Update()
{
Vector3 movementX = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movementX * Time.deltaTime * EnginePower.pwrOfEngine;
Vector3 movementY = new Vector3(0f, Input.GetAxis("Vertical"), 0f);
transform.position += movementY * Time.deltaTime * EnginePower.pwrOfEngine;
}
}
And here is the engine power script
public class EnginePower : MonoBehaviour
{
public float powerEng;
public static float pwrOfEngine;
void Start()
{
}
// Update is called once per frame
void Update()
{
pwrOfEngine = powerEng;
}
}
I feel like I'm missing something simple here but i can't quite remember or find an answer to what that thing is.
Any ideas?
Your answer
Follow this Question
Related Questions
Preventing smooth turning depending on input angle? 0 Answers
Move like 2D sonic in 3D space around in a spiral 1 Answer
Player not moving in the right direction instantly 1 Answer
how to shoot on different direction while moving away 1 Answer
How can i detect a collision with many Terrains?, since my collider is not working? 0 Answers