ina
November 7, 2012, 8:12am
1
var go:GameObject;
var goleaveblank:GameObject;
private var go_assignme:GameObject;
Suppose you have three exposed game objects. Only go is assigned - say - a cube in Hierarchy.
go_assignme = goleaveblank || go; // a || default value
assuming goleaveblank=null, will the default value always be assigned, as in: go_assignme = go;
?
fafase
November 7, 2012, 11:07am
2
This should not work. || is a logical operator and should only return boolean. C# would return an error. I would guess the compiler is converting go_assignement to a boolean so that you do not see any error but with C# it shows right on.
You might as well go with the ternary operator:
GameObject obj = goleaveblank ? goleaveblank:go;
If goleaveblank is null then go is return.
Note this is just a fancy way for:
GameObject obj;
if(goleaveblank)obj = goleaveblank;
else obj = go;
EDIT: Based on Izitmee comment I just add his version:
GameObject obj = goleaveblank??go;
All credits to him on that one.