I’ve been trying to create an OR statement using several variables, such as bools, floats, ints, but the console always neglects it. So I’ve narrowed it down to Setting a Float to a Random.Range, however, although this code runs through the console, there is virtually no effect. Can someone tell me what’s going wrong?
using UnityEngine;
using System.Collections;
public class RandomCardBack : MonoBehaviour
{
public Material first;
public Material second;
private float turn;
void Awake()
{
turn = Random.Range(1, 1.1f);
}
void Update()
{
if (turn == 1)
{
gameObject.renderer.material = first;
}
if (turn == 1.1f)
{
gameObject.renderer.material = second;
}
}
}
Random.Range(1,1.1f) will return a float between 1 and 1.1 inclusive, so most of the time both your if statements will be false as the result will rarely be exactly those 2 numbers. There are lots of floats between those 2 values!
Use the int version instead, but with the int version the max value is exclusive so you need it to be one higher than the largest value you want, like: Random.Range(0,2)
And have your if statement test for 0 or 1