In know it is pretty basic question but I could not find best solution for this.
I want value between two state for example 1 or -1. No other value allowed for this.
I know using condition but I want unity way of doing this. Please expert provide some suggestion in this.
Your question is lacking some important information. fafase actually answered the question “as it is” since you didn’t mention that you want to randomly choose one of the “states”.
Anyways if you want to generate randomly either (1) or (-1) you just do this:
var val = Random.Range(0,2)*2-1;
Random.Range(0,2) (!!with integer values!!) returns either 0 or 1
You multiply the result by 2 so the value is 0 or 2
subtract 1 so the 0 becomes -1 and the 2 becomes 1