how do I use the same triggercollider for multiple objects?
I am trying to get several objects to lerp between two colors using ontriggerenter, this is working fine. however I want to use the same triggercollider for all of them instead of having one for each. How do I do this?
also, now the script is attatched to each object I that is learping, is it possible to just have it in one spot and let each gameobject that needs it find it and apply it to that object?
Im very new at this so all help is appreciated! Thank you!
This is the script at the moment:
using UnityEngine; using System.Collections;
public class Colorshift : MonoBehaviour {
public Color startcolor; public Color endcolor; public float duration = 5; public GameObject[] Löv;
private bool colorize;
private float t = 0;
// Use this for initialization
void Awake ()
{
gameObject.GetComponent<Renderer>().material.color = startcolor;
colorize = true;
}
void OnTriggerEnter(Collider other)
{
if (colorize == true) {
if (gameObject.CompareTag ("1"))
{
StartCoroutine ("Fade");
t = 0;
colorize = false;
}
}
}
IEnumerator Fade()
{
while (transform.GetComponent<Renderer> ().material.color.a <= 0)
{
transform.GetComponent<Renderer> ().material.color = Color.Lerp (startcolor, endcolor, t);
yield return null;
}
}
void Update ()
{
if (t < 1)
{
t += Time.deltaTime / duration;
}
if (Input.GetKeyDown("space"))
{
t = 0;
}
}
Your answer
Follow this Question
Related Questions
(C#) Bullet Damage , OnCollisionTrigger2D not working,(C#) Bullet Damage, Trigger not working. 2 Answers
OnTriggerExit does not work 0 Answers
OnTriggerEnter does not work on placed terrain trees 0 Answers
Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer
How do trigger colliders and the Layer Collision Matrix interact? 0 Answers