Rotating a GameObject


English (Auto-generated)

Hi everyone in this cast, we work on a simple rotating animation which will let us focus a bit on the transform class and transform property which we will use later on. So every object, any scene has the transform component and this includes the directional light and the main camera game component. So the transform component is stores or is a reference to the position, rotation and scale of an object in a scene. Now, if you think about it, every game object which is part of the game world or scene has to be positioned somewhere, it can be made bigger or smaller and rotated clockwise or counterclockwise. So to gain access to this component via a C sharp script, we actually use the transform property. So out here you can see I have this cube and parent this is the cube parent. It has a child which is this sphere. So for us we will be dealing with the cube and any script that we add to the cube also applies to its child sphere. And out here you can see that I've added a script called rotation which is empty to the cube parent. Okay, so let me go ahead and open this up here. There's nothing in the rotation script as yet. So transform is a class in unity and each game object has one and the class is spelt with an uppercase T. Where as transform with a lower case T. Is a property which returns a transformed instance associated with a game object which in this case is our cube. So what we're going to do is in our scene, we are going to rotate this cube clockwise and then anti clockwise or counterclockwise. Okay, so let's go back here and this will be done. Our code will be written, it's just one line of code, but it's going to be written in the update method. Okay. So we'll use the transform property, which is an instance of the transform class and it's associated with the cube object, which is already attached to our cube game object. So this is how we will type it with a lower case T. And then we will use the rotate method out here, which is going to take as an argument a correct
87 Views 0 Likes 0 Comments

In this cast we will discuss rotating a GameObject using the transform property. We will trotate an object along the x, y and z axis

Leave a comment (supports markdown format)