- Home /
texture changing when standing on a trigger
I wanted something like a runic symbol on the ground/walls which lights up (texture changes) when the player touches a trigger. After a while, I want it to switch back to the original texture, to create the illusion as if it is lighting on and off.
Can you also help me with activating multiple runes (more than two must be activated in order for this to work) in a sequence/without order to open (destroy with play animation) a GameObject door?
Preferrably I would like them in C#. Thanks in advance!
Answer by deltamish · Feb 07, 2013 at 02:06 AM
Hi, what you can do is you can use OnTriggeEnter and OnTriggerExit
Create a Collider over target area(where you want the player to collide) and add material and meshrenderrer to it Add a collider(Character Controller would be fine too) to the player and tag player object which has the collider as Playe Add this script to the trigger texture(Note The script which i have written nedds both collider and texture on the same object it is so because you mentioned it should change when player steps on it,Ifwnat the script that works with collider and texture on differnet object please do ask
using UnityEngine;
using System.Collections;
public class TextureChanger: MonoBehaviour {
public Texture2D Normal;
public Texture2D Over;
void OnTriggerEnter(ply:Collider){
if(ply.tag == "Player"){
renderer.material.mainTexture = Over;
}
}
void OnTriggerExit(plyext:Collider){
if(plyext.tag == "Player"){
renderer.material.mainTexture = Normal;
}
}
}
Nnte
You mentioned that you wanted to activate multiple runes didyou mean it using same trigger
What do you mean by
sequence/without order to open
(destroy with play animation)*
Please do explain more about your question(Second part )
Oh. Yeah, sorry about the lack of explanation. I meant like having multiple of these switches/runes on the floor in different areas, and they all must be activated in order for a door to open. So more than one basically must be activated in order for the door to open. And thanks for your excellent support!
And don't $$anonymous$$d about the "Destroy and play animation" part. I got everything else undercover.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
C# - Problem with trigger that won't activate 1 Answer
Factory script not working 0 Answers
play animation on keypress if in range 3 Answers