Build a cannonball.
A sphere
Double-click Script
Go to Editor
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classAcc:monobehaviour {5 6 //Use this for initialization7 PublicTransform Q;8 intSpeed= -;9 voidStart () {Ten One } A - //Update is called once per frame - voidUpdate () { the floatx = Input.getaxis ("Horizontal") * Time.deltatime * speed;//move around - floatz = Input.getaxis ("Vertical") * Time.deltatime * speed;//move back and forth - //main Camera Object movement -Transform. Translate (x,0, z); + - if(Input.getkeydown (KEYCODE.MOUSE0)) + { ATransform n =(Transform) instantiate (q,transform.position,transform.rotation); atVector3 f =transform. Transformdirection (Vector3.forward); -N.rigidbody.addforce (f* -); - } - -Print (x+"--"+z); - } in}
Public Transform Q;
Build a Cannonball Q
Transform
Transform Transform
Inherits from Component,ienumerable
Position, rotation and scale of a object.
The position, rotation, and scaling of the object.
Every object in a scene has a Transform. It's used to store and manipulate the position, rotation and scale of the object. Every Transform can has a parent, which allows you to apply position, rotation and scale hierarchically. The hierarchy seen in the hierarchy pane. They also support enumerators so can loop through children using:
Each object in the scene has a transform. Used to store and manipulate the position, rotation, and scaling of objects. Each transform can have a parent that allows you to apply positions, rotations, and scales hierarchically. You can view hierarchy relationships in the hierarchy panel. They also support counters (enumerator), so you can use loops to traverse sub-objects.
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public void Awake() {foreach (Transform child in transform) {child.position += Vector3.up * 10.0F;}}}
// Moves all transform children 10 units upwards!//向上移动所有变换的子物体10个单位for (var child : Transform in transform) {child.position += Vector3.up * 10.0;}
See also: Physics class.
Variablesvariables
- Positionthe position of the transform in world space. The position of transform in world space coordinates.
- Localpositionposition of the transform relative to the parent transform. The position of the transformation relative to the parent.
- Euleranglesthe rotation as Euler angles in degrees. Rotates as a Euler angle.
- Localeuleranglesthe rotation as Euler angles in degrees relative to the parent transform ' s rotation. Rotates the rotation angle as a euler angle, relative to the parent's transformation.
- Rightthe Red axis of the transform in world space. The red axis of the world Space coordinate transformation. The x-axis.
- UpThe Green axis of the transform in world space. The green axis transformed in world space coordinates. That is the y-axis.
- Forwardthe Blue axis of the transform in world space. The blue axis of the world Space coordinate transformation. That is, the z axis.
- Rotationthe rotation of the transform in world space stored as a quaternion. In the World Space coordinate object transforms the rotation angle as the quaternion storage.
- Localrotationthe rotation of the transform relative to the parent transform ' s rotation. The angle of rotation of an object's transformation from the angle of rotation in relation to the parent.
- Localscalethe scale of the transform relative to the parent. Scaling relative to the parent object transformation.
- Parentthe parent of the transform. The parent of the object transformation.
- Worldtolocalmatrixmatrix that transforms a point from world space to local space (Read only). The point of the matrix transformation shifts from world coordinates to its own coordinates (read-only).
- Localtoworldmatrixmatrix that transforms a point from the local space into the world space (Read only). The point of the matrix transformation shifts from its own coordinates to world coordinates (read-only).
- Rootreturns the topmost transform in the hierarchy. Returns the highest-level transformation.
- Childcountthe number of children the Transform has. The number of sub-objects transformed.
- Lossyscalethe global scale of the object (Read only). Global scaling of objects (read-only).
Functionsfunction
- Translatemoves the transform in the direction and distance of translation. Move the transform in the direction and distance of the translation.
- Rotateapplies a rotation of eulerangles.z degrees around the z axis, eulerangles.x degrees around the x axis, and Eulerang Les.y degrees around the y axis (in this order). Applying the angle of rotation of a Euler angle, eulerangles.z degrees around the z-axis, eulerangles.x degrees around the x-axis, eulerangles.y degrees around the y-axis (in this order).
- Rotatearoundrotates the transform about axis passing through point in world coordinates by angle degrees. Rotates an object by the point axis of the world coordinates according to the angle degree.
- Lookatrotates the transform so the forward vectors points at/target/' s current position. Rotates the object so that the forward vector points to the current position of the target .
- Transformdirectiontransforms direction from the local space to the world space. From its own coordinates to the world coordinate transformation direction.
- Inversetransformdirectiontransforms A direction from world space to local space. The opposite of Transform.transformdirection. The transformation direction is from world coordinates to its own coordinates. The opposite of Transform.transformdirection.
- Transformpointtransforms position from the local space to the world space. Transforms the position from its own coordinates to world coordinates.
- Inversetransformpointtransforms position from World space to local space. The opposite of Transform.transformpoint. Transforms the position from world coordinates to its own coordinates. The opposite of Transform.transformpoint.
- Detachchildrenunparents all children. All sub-objects dissolve the parent-child relationship.
- Findfinds a child by name and returns it. Find the sub-object by name and return it.
- Ischildofis This transform a child of the parent? Is this transformation a child of the parent?
Inherited membersInheriting membersInherited VariablesInheritance Variables
- Transformthe Transform attached to the gameobject (null if there is none attached). Transform attached to Gameobject (game object) (empty if no attach).
- Rigidbodythe Rigidbody attached to the gameobject (null if there is none attached). Rigidbody attached to Gameobject (game object) (empty if no attach).
- Camerathe Camera attached to the gameobject (null if there is none attached). Camera is attached to the Gameobject (game object) (empty if no attach).
- Lightthe light attached to this gameobject (null if there is none attached). Light is attached to the Gameobject (game object) (empty if no attach).
- Animationthe Animation attached to the gameobject (null if there is none attached). Animation attached to Gameobject (game object) (empty if no attach).
- Constantforcethe Constantforce attached to the gameobject (null if there is none attached). Constantforce attached to Gameobject (game object) (empty if no attach).
- Rendererthe Renderer attached to the gameobject (null if there is none attached). Renderer attached to Gameobject (game object) (empty if no attach).
- Audiothe Audiosource attached to the gameobject (null if there is none attached). Audiosource attached to Gameobject (game object) (empty if no attach).
- Guitextthe Guitext attached to the gameobject (null if there is none attached). Guitext attached to Gameobject (game object) (empty if no attach).
- Networkviewthe Networkview attached to this gameobject (Read only). (Null if there is none attached) Networkview attached to Gameobject (game object) (read-only) (empty if no attach).
- Guitexturethe guitexture attached to this gameobject (Read only). (Null if there is none attached) Guitexture attached to Gameobject (game object) (read-only) (empty if no attach).
- Colliderthe Collider attached to the gameobject (null if there is none attached). Collider attached to Gameobject (game object) (empty if no attach).
- Hingejointthe Hingejoint attached to the gameobject (null if there is none attached). Hingejoint attached to Gameobject (game object) (empty if no attach).
- Particleemitterthe Particleemitter attached to the gameobject (null if there is none attached). Particleemitter attached to Gameobject (game object) (empty if no attach).
- Gameobjectthe Game Object This component was attached to. A component is always attached to a game object. The game object attached to the component. A component is always attached to a game object.
- Tagthe tag of this game object. The label of the game object.
- Namethe name of the object. The name of the object
- Hideflagsshould The object is hidden, saved with the scene or modifiable by the user? Is the object hidden, stored in the scene, or modified by the user?
Inherited FunctionsInheritance function
- Getcomponentreturns the component of type if the game object has one attached, null if it doesn ' t. If a game object has an attachment, return to Typ A component of type E, or null if not.
- Getcomponent.<t>
- Getcomponentreturns the component with name type if the game object has one attached, null if it doesn ' t. If a game object has an append, the return name The word type component, or null if it is not.
- Getcomponentinchildrenreturns the component of type type in the Gameobject or any of its children using depth first search . Returns a type component that uses a depth-first search in gameobject or any of its sub-objects, returning only the active component.
- Getcomponentinchildren.<t>
- Getcomponentsinchildrenreturns all components of type type in the Gameobject or any of its children. Returns all type components in Gameobject or any of its sub-objects
- Getcomponentsinchildren.<t>
- Getcomponentsreturns all components of type type in the Gameobject. Returns all type components in the game object.
- Getcomponents.<t>
- Comparetagis this game object tagged tag? Does the game object have tagged tags?
- Sendmessageupwardscalls the method named MethodName on every monobehaviour in this game object and on every ancestor of th E behaviour invokes a method called MethodName on each monobehaviour and each behaviour ancestor of the game object.
- Sendmessagecalls the method named MethodName on every monobehaviour in this game object. A method called MethodName is monobehaviour on each of the game objects.
- Broadcastmessagecalls the method named MethodName on every monobehaviour in this game object or any of its children. Call the method named MethodName on each monobehaviour of the game object and on all its sub-objects.
- Getinstanceidreturns The instance ID of the object. Returns the instance ID of the object
- Tostringreturns the name of the game object. Returns the name of the game object.
Inherited Class FunctionsInheriting class functions
- Operator booldoes the object exist? Does the object exist?
- Instantiateclones the object original and returns the clone. Clones the original object and returns the cloned object
- Instantiate.<t>
- Destroyremoves a gameobject, component or asset. Delete a Game object, component, or resource
- Destroyimmediatedestroys the object obj immediately. It is the strongly recommended to use Destroy instead. Immediately destroy the object obj, it is strongly recommended to use destroy instead.
- Findobjectsoftypereturns a list of all active loaded objects of type type. Returns the list of all activated loaded objects of type
- Findobjectoftypereturns the first active loaded object of type type. Returns the type of the first activated loaded object.
- Operator ==compares If two objects refer to the same compare if two objects are the same
- Operator!=compares If two objects refer to a different object comparison if two objects are different
- Dontdestroyonloadmakes the object target not being destroyed automatically when loading a new scene. The target object is not automatically destroyed when the new scene is loaded.
int speed=50;
Is the step size
if (Input.getkeydown (KEYCODE.MOUSE0))
Press the left mouse button
Transform n = (Transform) instantiate (q,transform.position,transform.rotation);
Create a new shell
Instantiate is an object type that requires casting
Vector3 f = transform. Transformdirection (Vector3.forward);
Three-dimensional coordinates vector3.forward 0 0 1 forward
N.rigidbody.addforce (f*2000);
To run and break the Afterburner
At last
Click on the camera to drag the shells to the defined public variables
520 520 novel novel 520 novel 520 5200 novel 5200 5200 novel 5200 novel web
Www.520books.com
http://www.cnblogs.com/goodchenqing/
Http://blog.sina.com.cn/goodchenqing
http://goodchenqing.bokee.com/
http://blog.csdn.net/abc288abcd/article/category/2786567
Unity3d Learning Tutorial C # Launch shells