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

Using Leap to Change color of Objects.

Discussion in 'Scripting' started by fredyyanez, Jun 3, 2015.

  1. fredyyanez

    fredyyanez

    Joined:
    Jul 8, 2014
    Posts:
    33
    I want to use the leap to change the color of an object ( ex a cube) when I touch it.

    I've tried using OnTriggerEnter, but I have to make the cube a rigid body. Therefore, as soon as I touch it it moves. Is there a way to fix an object to a certain point and when the "hands: in the leap go through it change the color of the object? ( I know how to change the color using render, so essentially I just need to be able to detect when the trigger happens and I can take it from there)


    Thanks,

    Alfredo Yanez
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    You could set the rigidBody to kinematic, that way it won't move when collided, then use OnCollisionEnter();
     
  3. fredyyanez

    fredyyanez

    Joined:
    Jul 8, 2014
    Posts:
    33

    Thanks for the reply.
    Ive done that and I've also fixed the location of the object.
    My code is the following:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Collide : MonoBehaviour {
    5.  
    6.     void OnCollisionEnter(Collision other) {
    7.         Debug.Log("Contact was made!");
    8.  
    9.     }
    10.    
    11.  
    12. }
    13.  
    This code is attached to the object that I want to change color. I have a simple debug statement to see if ti works.

    So far It hasn't printed anything.

    Thanks!!
     
  4. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    My mistake. isKinematic disables collision detection.

    Instead, make the hand colliders triggers, and use OnTriggerEnter;

    Working scene attached:
     

    Attached Files: