Look at , lerp , Destroy gameObject - Unity

Look at
 Lets just discuss about the code and look at use. I have used the look at function to change the direction of the camera while the game is playing. As i have created a character. Which falls on the ground. Now In order to show the ball falling look at function is used that shows while playing.


Now here the script is added where in the target section i have added a moving cube. That the camera demands the object on which it have to focus. Now lets see the code that simple to understand. 


Now here the Transform object reference is given which demands a particular object. That is given be given in the picture above shown. 

Lerp 
Vector 3.lerp is used to change the position of an object between two points.
In this section i have added the lerp attribute to the camera. So the camera will move between two points. Lets see the code things will get more clear.

Here on the first line a Vector3 is declared. Where in the awake transform position will assign the current position of the object. Then in update the position change method will be called. Where  two positions are defined. And below that it take the command. On which pressing the particular key. It will change the camera position.   
Camera Positon 1:

Camera Position 2:

Now the pressing of Q and E changes the camera position.

Destroy GameObject 
As in unity every character is considered as object. Now if you want to destroy the the object this code is needed.
Now the object that will be added in the others will be destroyed. If you want to destroy the object after some time. Then you have seen the code in the comment Destroy(other,3f) 3f means that it will destroy the object after 3 seconds. Hence the space occupied will be empty. 

Comments

Popular posts from this blog

How to move an object in Unity 3D

Input.Getaxis, OnMouseDown, GetComponent< > - Unity Scripts

Vector Math - Unity