Lam Cao's Blog

A Journey in Game Dev


Category: tips & tricks

[Unity Tips] Did you know that you can have multiple inspectors at the same time?

I often have to switch to the debug view of the inspector to check out backing fields and other hidden stuff. I find it very helpful to just have both views at the same time.

  • Click on the tiny hamburger button on the top right corner.
  • Choose “Add Tabs”
  • Choose “Inspector”
  • Repeat as many times as you like.

How to use Lerp right.

Lerp, or linear interpolation, is a super useful function we all love. However, I often see devs use it in some weird way. I feel like they never bothered to read the documentation. Well, these devs probably didn’t. Here is an example of how not to use Lerp right.

transform.position = Vector3.Lerp(transform.position, endPoint, Time.deltaTime * speed);

I have seen it in random online tutorials, on Unity Answers and StackOverflow. If you know how it works, then you know the code example above makes no sense! Let’s discuss why.


[Unity Tips] Tint color in PlayMode

We all have been there tweaking a scene, making a ton of changes just to realize we are in PlayMode for the whole time. It is frustrating. Let’s not make the same mistake over and over.

We can set Playmode tint in Edit -> Preferences -> Colors to something extreme like red. Our eyes will just stop us from making any serious changes during PlayMode.


[Unity Tips] Use CompareTag instead of string.Equals

Comparing tags is a thing we all do in every game project at some point but not everyone seems to know about the existence of CompareTag. Unity could really have done a better job documenting this useful method.

In short, use obj.CompareTag("someTag") instead of string comparisions such as obj.tag=="someTag". CompareTag is much faster and will log an error if a tag is not defined, which is a very good thing.

In case of comparing against a list, use list.FirstOrDefault(t=>obj.CompareTag(t))!=null rather than something like list.Contains(obj.tag) for the same reasons.