- Home /
Fade into other object on touch/drag.
Hey, here's what I'm trying to accomplish.
Let say I have two objects layed on top of each from the POV of the player (camera). What I want to do is have one overlap and hide the other, then when the user touches the object or click drags on the object it makes the top object go transparent where it was touched.
E.g. you have a blue person and as you run your finger over him his colors change to red where you touch.
Answer by ReeRoo · Mar 15, 2015 at 10:34 PM
If you put this script in the update method it should change whatever you touch to change to red as long as it has a collider attached and is tagged as hitobject.
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position );
RaycastHit hit;
if ( Physics.Raycast(ray, out hit) && hit.gameObject.tag == "hitobject")
{
hit.gameobject.renderer.material.color = Color.red;
}
}
Yep you could specify your own color, simply replace "Color.red" with new Color(1F, 0F, 0F, "aplha value here" F) if you would like a transparent red, or any other RGBA colour.