How to make a character controller through another script
I am making a game with 9 character and using the move script it gets very repetitive, as i have to make a move script for each and every one of the nine characters. So instead what i intend to do is to make one move script on an empty game object and all of the characters (when active) can pass a speed value and jump value to the move script, and from there the script can move the character can move according to their speed/jump values.
I am testing out this feature on only one character before i add it to every character so i only have one character mentioned in the script
This is the move script :#
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour{
public Rigidbody2D Rigidbody2D;
public void Motion (float speed, float jump){
if (Input.GetKeyDown (KeyCode.W)) {
Rigidbody2D.position = new Vector2 (Rigidbody2D.velocity.x, jump);
}
if (Input.GetKeyDown (KeyCode.A)) {
}
if (Input.GetKeyDown (KeyCode.D)) {
}
}
}
This is the Character Code :
using System.Collections;
public class scout_Move : MonoBehaviour{
public static float Speed = 1.5f;
public static float Jump = 5f;
Movement Move = new Movement ();
void Update () {
Move.Motion(Speed, Jump);
}
} Thank you so so so so much for the help this has been bugging me for 3 days now
Your answer
Follow this Question
Related Questions
How do I make player attack with LMB if the enemy is within range? 0 Answers
Trying to "condense" a lot of verbose code, for an inventory system. Don't know where to start. 0 Answers
How to make a character Jump given a certain condition 0 Answers
Character's jumping mechanism stuck into something invisible 1 Answer
Character Controller creates invisible wall where he spawns... 0 Answers