I have an editor window script with a button. When the button is pressed I would like an object, to move downwards until it meets a collider (where the object’s center stops).
From:

To:

Any ideas how I could do this?
Would I be able to use a raycast somehow?
Problem solved:
#pragma strict
class newwindow extends EditorWindow {
var objecttomove : GameObject;
var collisionobject : GameObject;
var shouldimove = true;
@MenuItem ("Window/testeditor")
static function Init () {
// Get existing open window or if none, make a new one:
var window : newwindow = ScriptableObject.CreateInstance.<newwindow>();
window.Show();
}
function OnGUI() {
objecttomove = EditorGUILayout.ObjectField("Object: ",objecttomove, GameObject, true);
collisionobject = EditorGUILayout.ObjectField("collision object: ",collisionobject, GameObject, true);
if(GUILayout.Button("Move down")) {
move();
}
if(GUILayout.Button("reset move")) {
shouldimove = true;
}
}
function move() {
if (shouldimove == true) {
objecttomove.gameObject.transform.position.y = objecttomove.gameObject.transform.position.y-0.01;
if (objecttomove.gameObject.renderer.bounds.Intersects(collisionobject.gameObject.renderer.bounds)) {
shouldimove = false;
}
move();
}
}
}
…but you have to click the ‘reset move’ button after you move an object