:EDIT:
Here's an example. Make a script called "ExampleSO" and replace the contents with:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class ExampleSO : ScriptableObject
{
public float stashedVar = 0f;
}
Make a script called "ExampleWriter" and replace the contents with:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleWriter : MonoBehaviour
{
public float scaling = 2f;
public float scaledInput = 0f;
public ExampleSO exampleSO = null;
// Update is called once per frame
void Update()
{
if(exampleSO!=null)
{
scaledInput = scaling * (Input.GetKey(KeyCode.LeftArrow) ? 1f : 0f);
exampleSO.stashedVar = scaledInput;
}
}
}
Make a script called "ExampleReader" and replace the contents with:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleReader : MonoBehaviour
{
public float display = 0f;
public ExampleSO exampleSO = null;
void Update()
{
if(exampleSO!=null)
{
display = exampleSO.stashedVar;
}
}
}
Create an instance of the ExampleSO, add the ExampleWriter to a game object, and put the ExampleSO instance into the ExampleWriter slot.
Highlight the game object holding ExampleWriter and run it. Push the left arrow key and see the value toggle 0/2.
Click the ExampleSO instance. Nothing is happening there now. Click back on the game object, and now it doesn't update either.
If you have the ExampleReader on the same game object then it won't work at all. ExampleReader will read fine, if you have it on a separate GameObject, but again if you click off and click back then it stops responding.