Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to automacicaly random rotate pefab during placement in editor in unity 4.5.3?

I can make it autorotate in game(at start) but I want it to be visible in editor and at fixed rotation after placement.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Found it! Attribute [ExecuteInEditMode] does what I want

[ExecuteInEditMode]
public class RandomRotation : MonoBehaviour {
    void Start () {
#if UNITY_EDITOR
        this.transform.Rotate(0, MyRandom.Rotate(this.GetInstanceID()), 0);
        this.transform.localScale = MyRandom.Scale (this.GetInstanceID(), 0.4f, 1f);
        Debug.Log("Editor");

#else
        Debug.Log("Game");
#endif
    }
}
share|improve this answer
    
isn't editor scripting in unity pretty cool –  jhocking Aug 15 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.