Useful snippets that I often use in my projects and that I'm glad to share.
They are mostly begginers' code (well, just like me 😊) but I hope they might help others who, like me, started to learn coding from generous coders' community who shared and continue to share their experience freely.
In addition, please have a look at the use of coding in my personal work here and enjoy !
Feel free to contact me for any questions or advice on improving the snippets posted.
- RandomToggle.js - Method to toggle randomly between two given values.
- CreatePointAroundCircle.js - Method to make an object move around a circle. Demo with p5 library.
- RotateCameraAroundTarget.cs - Method to orbit camera (or any object of your choice) around a target. I usually put this script on my Main Camera to orbit (and debug) a specific scene component at runtime. It's also perfect for demos.
- ConstantLerp.cs - Constant Vector3.Lerp from A to B with speed
- DetectDirectionalRotation.cs - Detect if an object/player is rotating clockwise or anti-clockwise
- AddComponent_TextMesh.cs - Create a TextMesh component in realtime.
- DistanceFromTarget.cs - Methods to calculate the distance between two Gameobjects.
- OrthoScreenCameraBoundaries.cs - Some examples of screen positions on an Orthographic camera (Center, TopLeft, TopRight, BottonLeft, BottonRight)
- CallKeyDownWithDelay.cs - Method to trigger a KeyDown (analog or bool) with a given delay. Let you control the rate a button triggers an action.
- MapValueToRange.cs - Method to map a value between a given range.
- CallFunctionAtInterval.cs - Method to call a function at a given interval.
- PrintOnlyOnceInUpdateMethod.cs - Method that will call a function only Once in the Update() method.
- LookAtTarget.cs - Look at a target (seperate XYZ axis)
- DetectDevice_PC_Android.cs - Detect easily if your app is running on an Android device or in Play mode in Unity engine. This little piece of code frees you from using public user booleans switched manually between PC and Android.
- XYZ_TO_AdobeRGB.cs - Method that returns an Adobe RGB vector from XYZ coordinates. I created this function to convert my xyz movement to color. You can find some samples of my work here.
- ScreenArray.cs - Get a Screen Array from TopLeft to BottomRight corner with borders and illustrate with spheres on an Orthographic camera.
- Editor folder - When using a plugin script that is not an asset from the Package Manager or that you got from the community, for ex this awesome script for Replacing a Prefab by another, don't forget to put it in a folder called Editor. Thus, it will not be compiled when building your game, nor will it prompt errors like are you missing an assembly reference?. More info on Replace With Prefab awesome adventure here.