Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Gizmo Draw

Discussion in 'Scripting' started by woodygoody, Sep 20, 2012.

  1. woodygoody

    woodygoody

    Joined:
    Aug 23, 2011
    Posts:
    164
    Hi :D
    I used this code to draw my custom icon in editor as gizmo icon for my timer game object:
    Original Code:

    Code (csharp):
    1. // Draws the Light bulb icon at position of the object.
    2. // Because we draw it inside OnDrawGizmos the icon is also pickable
    3. // in the scene view.
    4.  
    5. function OnDrawGizmos () {
    6.     Gizmos.DrawIcon (transform.position, "Timer.png", true);
    7. }
    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:

    Code (csharp):
    1. // Draws the Light bulb icon at position of the object.
    2. // Because we draw it inside OnDrawGizmos the icon is also pickable
    3. // in the scene view.
    4.  
    5. var Gizmo : GameObject;
    6.  
    7. function OnDrawGizmos () {
    8.     Gizmos.DrawIcon (transform.position, Gizmo , true);
    9. }
    Console Report:

    Code (csharp):
    1. No appropriate version of 'UnityEngine.Gizmos.DrawIcon' for the argument list '(UnityEngine.Vector3, UnityEngine.GameObject, boolean)' was found.
    What is the error message meaning ?
     
  2. Brian-Stone

    Brian-Stone

    Joined:
    Jun 9, 2012
    Posts:
    222
    You're trying to pass a GameObject in the second argument of DrawIcon(). The function clearly requires a String for that argument.

    Gizmos.DrawIcon() Documentation:


    static function DrawIcon (center : Vector3, name : String, allowScaling : boolean = true) : void
     
  3. woodygoody

    woodygoody

    Joined:
    Aug 23, 2011
    Posts:
    164
    This my new code but no gizmos drawn !!!!!!!!!!

    Code (csharp):
    1. var Gizmo : Texture2D;             // place here gizmo texture "Timer.png"
    2. var GizmoString;                     // variable to save texture name as string
    3. function Update()
    4. {
    5. GizmoString = Gizmo.name.ToString; // convert texture name to string
    6. }
    7. function OnDrawGizmos ()                // draw gizmo function
    8. {
    9.     Gizmos.DrawIcon (transform.position, GizmoString, true);
    10. }
    Console Error
    Code (csharp):
    1. InvalidCastException: Cannot cast from source type to destination type.
    2. Timer_Gizmo.OnDrawGizmos () (at Assets/Circuspheres/Timer/Scripts/Timer_Gizmo.js:19)
    3.  
     
    Last edited: Sep 22, 2012
  4. woodygoody

    woodygoody

    Joined:
    Aug 23, 2011
    Posts:
    164
    No Solve ...
     
  5. Noxury

    Noxury

    Joined:
    Mar 8, 2015
    Posts:
    22
    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.
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,198
    Lovely of you to help someone with a six year old problem.
     
    xVergilx likes this.
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,294
    Bonus points for helping with UnityScript code.

    Although the advice is kinda useful, for the future generations.