Inadvertently learned things!

So, when Ben asked to finish off the script, I thought he meant to have the sliders update the obstacle in the Editor! I didn’t know he only intended it to work while playing the game, so I ended up with this:

using UnityEngine;

[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Oscillator : MonoBehaviour
{

    [SerializeField] Vector3 movementVector;

    //todo remove from inspector later
    [Range(0, 1)] [SerializeField] float movementFactor;

    Vector3 startingPos;

	// Use this for initialization
	void Start ()
	{
        startingPos = transform.position;
	}
	
	// Update is called once per frame
	void Update ()
	{
	    transform.position = startingPos + (movementVector * movementFactor);
    }
}

The [ExecuteInEditMode] part allowed the sliders to affect the position of the object while in the Editor, which was cool, but did weird things, like not allow me to affect the position directly (it would stop me doing that).

So… sometimes misunderstanding leads to discovery! Thank you Ben!

1 Like

Very nice Zebulon, well done…

Slightly tongue-in-cheek, but here’s another one for you… :wink: :stuck_out_tongue:


See also;

Privacy & Terms