x


Extending the Editor with C#

Hi guys. I'm switching to C# from Js and I'm trying to rewrite the JS example of Extanding the Editor. I keep getting a bunch of errors.

Here's my code:

using UnityEngine;
using System.Collections;

public class LookAtPoint : MonoBehaviour {
public Vector3 lookAtPoint;

// Use this for initialization
void Start () 
{
    lookAtPoint = Vector3.zero;
}

// Update is called once per frame
void Update () 
{
    transform.LookAt(lookAtPoint);
}
}

and here's the Editor code:

using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(LookAtPoint))]
public class LookAtPointEditor : Editor
{
    public override void OnInspectorGUI()
    {
        target.lookAtPoint = EditorGUILayout.Vector3Field("Look At Point", target.lookAtPoint);
        if(GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
}    

I'm getting quite a few errors and I'm not sure where I am going wrong.

Thanks.

Kamil

more ▼

asked Jun 23 '11 at 11:47 AM

kamil.slawicki gravatar image

kamil.slawicki
96 12 12 15

can some1 please fix the editing of the editor code and tell em how to do it for the future?

Jun 23 '11 at 11:49 AM kamil.slawicki

Hilight the code and hit the button with the "0101010" on it...

Jun 23 '11 at 02:15 PM flaviusxvii
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Fixed it myself. I'm casting (LookAtPoint) on target every time.

more ▼

answered Jun 23 '11 at 12:31 PM

kamil.slawicki gravatar image

kamil.slawicki
96 12 12 15

In the future, when you're getting "Quite a few errors", consider posting what the errors are :)

Jun 23 '11 at 02:43 PM testure
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7712
x2371
x29

asked: Jun 23 '11 at 11:47 AM

Seen: 4231 times

Last Updated: Jun 23 '11 at 02:43 PM