I'm trying to get a Float variable from the script MainCharacterVarsScript, I would use this Float in this current script. The variable is called CharacterSpeed, both scripts are on the Game Object BaseCharacter. Right now I have a kinda backwards way of doing it trying to remake it into a new variable on this script. This is what I have currently, just me trying to get the component from the other script. I am getting the error on line 15 (the long one) telling me that I am using an unassigned local variable.
Condensed version of what I want:
To get a var from one script to another
1)Get float CharacterSpeed from MainCharacterVarsScript
2)Make it a usable float in my current script
3)Both on Game Object BaseCharacter
Thanks for reading and helping
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCharacterMove : MonoBehaviour {
float MoveSpeed;
// Use this for initialization
void Start () {
GameObject BaseCharacter = GameObject.Find ("BaseCharacter");
MainCharacterVarsScript mainCharacterVarsScript =
mainCharacterVarsScript.GetComponent<MainCharacterVarsScript>();
mainCharacterVarsScript.CharacterSpeed = MoveSpeed;
}
// Update is called once per frame
void Update () {
}
}