1. Unity comes with a trigger event
Every collider object in unity has events such as onmousedown, onmouseover, and so on, which are present in Monobehaviour scripts, and Monobehaviour is the base class for each script. These events are known according to the manual (the mouse calls onmousedown when clicked on Guielement (GUI Element) or collider (collision body), and is a trigger!
2. Destroying objects
In order not to consume system resources or to avoid a memory leak, when we destroy an object, we have to deal with what this object refers to!
The script introduced by this object script is null, destory the object introduced by this object script, and then destroys itself!
3, Vibration screen effect
Create a new script CameraShake.cs
usingUnityengine;usingSystem.Collections; Public classcamerashake:monobehaviour{ Public Static BOOLStartshake =false; Public Static floatseconds =0.0f; Public Static BOOLstarted =false; Public Static floatQuake =0.2f; PrivateVector3 CamPOS; Public BOOLis2d; voidStart () {CamPOS=transform.position; } voidlateupdate () {if(startshake) {transform.position= Random.insideunitsphere *quake; if(is2d) Transform.position =NewVector3 (transform.position.x, TRANSFORM.POSITION.Y, campos.z); } if(started) {Startcoroutine (Waitforsecond (seconds)); Started=false; } } Public Static voidShakefor (floatAfloatb) {seconds=A; Started=true; Quake=b; } IEnumerator Waitforsecond (floata) {CamPOS=transform.position; Startshake=true; yield return NewWaitforseconds (a); Startshake=false; Transform.position=CamPOS; }}
This script hangs on the camera and is called Where needed: Camerashake.shakefor (0.5f,0.1f)
Candycrush Candy Saga mini-game Summary