- Home /
get color of randomly generated objects
I've got many platform for whom there are 3 colors which are generated automatically, I'd like that after game starts and they all get their random color (red,green or blue) it will return all the colors of the platforms and in my main script using a trigger my ball can determine which color the platform he is going to collide with, if the ball isn't the same color of the platform - he will DIE
Answer by abi-kr01 · Mar 02, 2015 at 04:35 AM
using UnityEngine;
using System.Collections;
using System;
public class test : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if(other.transform.renderer.material.color==this.transform.renderer.material.color)
{
print(" keep roooling");
}
else
{
print(" die ");
}
}
}
add this to platform game-object. you can add extra condition as there are many things that will triger this script like other game objects that are avaible with coliders
Thank you so much, been struggling for days for such a silly little script haha, I feel retarded...
Your answer
Follow this Question
Related Questions
Create new mesh from script always black color even i change material. 1 Answer
Sprite dots spawn and have their own color, but they only show as wireframes? 0 Answers
A Javascript trying to access an image effect C# script 1 Answer
Totally new, is there something wrong with this switch script for color changes? 1 Answer