Hello!
( Sorry for the bad english in this entire text )
I have a plane ( water ) that raises by time.
This is the script for the raising water:
using UnityEngine;
using System.Collections;
public class WaterRise : MonoBehaviour {
public Vector3 raisespeed = new Vector3(0,5.0f,0);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
// WaitForSeconds(5);
transform.Translate(raisespeed * Time.deltaTime);
}
}
This is the WaterRise script. And it works. Now i have an other script, the MainMenu script. These are all written in c#. So, i have a toggleabble ‘‘radio button’’ in the MainMenu script. I want to increase the value of ‘‘raisespeed’’ ( so the plane moves faster ). How can i do this? I can’t figure out how to change the values of a script with other script. I want to change the Vector3(0,5.0f,0)
This is the script for the MainMenu ( i know its not actually a main menu ):
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
private bool fastmode = false;
void OnGUI () {
fastmode = GUI.Toggle (new Rect (25, 25, 100, 30), fastmode, "Fast mode");
}
void Update () {
if (fastmode == true) {
WaterRise = GetComponent("WaterRise") as WaterRise;
WaterRise.do public Vector3 speed = new Vector3(0,5.0f,0);
}
}
}
This code is a totally fail now.
Thanks for helping!
EDIT: I didn’t notice they were in different scenes. To fix this you will need to change your MainMenu to say something like:
void Start()
{
PlayerPrefs.SetInt("raisespeed", 5);
}
void OnGUI () {
fastmode = GUI.Toggle (new Rect (25, 25, 100, 30), fastmode, "Fast mode");
if(GUI.changed && fastmode == true)
PlayerPrefs.SetInt("raisespeed", 10);
else if(GUI.changed && fastmode == false)
PlayerPrefs.SetInt("raisespeed", 5);
}
void Update () {
}
Then change your waterrise script to be:
public Vector3 raisespeed;
// Use this for initialization
void Start () {
raisespeed = new Vector3(0, PlayerPrefs.GetInt("raisespeed"), 0);
}
That will do it for you.
More info on playerprefs can be found here: Unity - Scripting API: PlayerPrefs