Example #1
0
    /// <summary>
    /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
    /// Then apply the desired settings. Returns null if no collider exists.
    /// </summary>
    /// <param name="C"></param>
    /// <returns></returns>
    protected static SenseGlove_Touch GetTouchScript(Collider C, SenseGlove_GrabScript grabScript)
    {
        if (C != null)
        {
            C.isTrigger = true;
            SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
            if (script == null)
            {
                script = C.gameObject.AddComponent <SenseGlove_Touch>();
            }
            script.touch = C;
            script.SetSourceScript(grabScript);

            //also add a rigidbody
            Rigidbody RB = C.gameObject.GetComponent <Rigidbody>();
            if (RB == null)
            {
                RB = C.gameObject.AddComponent <Rigidbody>();
            }
            RB.useGravity  = false;
            RB.isKinematic = true;

            return(script);
        }
        return(null);
    }
    /// <summary>
    /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
    /// Then apply the desired settings. Returns null if no collider exists.
    /// </summary>
    /// <param name="C"></param>
    /// <returns></returns>
    private SenseGlove_Touch GetTouchScript(Collider C)
    {
        if (C != null)
        {
            C.isTrigger = true;
            SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
            if (script == null)
            {
                script = C.gameObject.AddComponent <SenseGlove_Touch>();
            }
            script.touch = C;
            script.SetSourceScript(this);
            script.CreateDebugObject(this.debugColliderColor);
            script.SetDebugLevel(this.debugMode);

            //also add a rigidbody
            Rigidbody RB = C.gameObject.GetComponent <Rigidbody>();
            if (RB == null)
            {
                RB = C.gameObject.AddComponent <Rigidbody>();
            }
            RB.useGravity  = false;
            RB.isKinematic = true;

            return(script);
        }
        return(null);
    }
 /// <summary>
 /// Get the SenseGlove_Touch of a specified collider. If none is present, create a new one.
 /// Then apply the desired settings. Returns null if the Collider is NULL.
 /// </summary>
 /// <param name="C"></param>
 /// <returns></returns>
 private SenseGlove_Touch GetTouchScript(Collider C)
 {
     if (C != null)
     {
         C.isTrigger = true;
         SenseGlove_Touch script = C.gameObject.GetComponent <SenseGlove_Touch>();
         if (script == null)
         {
             script = C.gameObject.AddComponent <SenseGlove_Touch>();
         }
         script.touch = C;
         script.SetSourceScript(this);
         return(script);
     }
     return(null);
 }