Hi
I used this code to draw my custom icon in editor as gizmo icon for my timer game object: Original Code:
// Draws the Light bulb icon at position of the object.
// Because we draw it inside OnDrawGizmos the icon is also pickable
// in the scene view.
function OnDrawGizmos () {
Gizmos.DrawIcon (transform.position, "Timer.png", true);
}
I need make icon file name “Timer.png” as variable I tried make next change but console gave me an error Original Code with some Changes:
// Draws the Light bulb icon at position of the object.
// Because we draw it inside OnDrawGizmos the icon is also pickable
// in the scene view.
var Gizmo : GameObject;
function OnDrawGizmos () {
Gizmos.DrawIcon (transform.position, Gizmo , true);
}
Console Report:
No appropriate version of 'UnityEngine.Gizmos.DrawIcon' for the argument list '(UnityEngine.Vector3, UnityEngine.GameObject, boolean)' was found.
var Gizmo : Texture2D; // place here gizmo texture "Timer.png"
var GizmoString; // variable to save texture name as string
function Update()
{
GizmoString = Gizmo.name.ToString; // convert texture name to string
}
function OnDrawGizmos () // draw gizmo function
{
Gizmos.DrawIcon (transform.position, GizmoString, true);
}
Console Error
InvalidCastException: Cannot cast from source type to destination type.
Timer_Gizmo.OnDrawGizmos () (at Assets/Circuspheres/Timer/Scripts/Timer_Gizmo.js:19)
You need to have a folder called Gizmos in the root of your project.
Read the Documentation. “The image file should be placed in the Assets/Gizmos folder.”
Your timer.png should be in there. Gizmos.DrawIcon unfortunatly looks only into that folder.