Scripts that are bound to the camera
Using unityengine;using System.collections;public class Abc:monobehaviour {//Set move speed public int velocity = 5;//setting will be initialized loaded object p Ublic Transform newobject = null;//Use this for initializationvoid Start () {}//Update is called once per framevoid UPDA Te () {///through the left and right arrow keys, or a, D letter key control the horizontal direction, the realization left, move to the right float x = Input.getaxis ("horizontal") * Time.deltatime * speed;//through the upper and lower arrow keys, or W, The S-letter key controls the vertical direction, realizes moving forward and backward, floats z = Input.getaxis ("Vertical") * Time.deltatime * speed;//moves the X-Z axis of the binding, i.e. the X, Z axis of the moving camera. Transform. Translate (x,0,z);//Determines whether to press the left mouse button if (Input.getbuttondown ("Fire1")) {//Instantiate command: Instantiate (the object to be generated, the position generated, the angle of rotation of the resulting object) Transform n = (Transform) instantiate (NewObject, transform.position, transform.rotation);//conversion direction Vector3 FWD = Transform. Transformdirection (Vector3.forward);//Add force to an object//unity5 before writing: N.rigidbody.addforce (FWD * 2800);n.getcomponent< Rigidbody> (). Addforce (FWD * 2800);} Determines whether to press the letter button Qif (Input.getkey (KEYCODE.Q)) {//Change the y-axis of the binding, i.e. change the y-axis of the camera. Transform. Rotate (0,-25*time.deltatime,0,space.self);} Determine whether to press the letter button Eif (Input.getkey (KEYCODE.E)) {transform. Rotate (0,25*time.deltatime,0,space.self);} Determines whether to press the letter button Zif (Input.getkey (keycode.z)) {//Rotates the y-axis of the binding, that is, the y-axis of the rotating camera. Transform. Rotate ( -25*time.deltatime,0,0,space.self);} Determines whether to press the letter button Xif (Input.getkey (keycode.x)) {//Rotates the y-axis of the binding, that is, the y axis of the rotating camera. Transform. Rotate (25*time.deltatime,0,0,space.self);} Determines whether to press the letter button Fif (Input.getkey (KEYCODE.F)) {//Move the y-axis of the binding, i.e. move the camera's y-axis. Transform. Translate (0,-5*time.deltatime,0);} Determines whether to press the letter button Cif (Input.getkey (keycode.c)) {//Move the y-axis of the binding, that is, the y-axis of the moving camera. Transform. Translate (0,5*time.deltatime,0);}}}
Script that binds to the launched ball
Using unityengine;using System.collections;public class Xiaomie:monobehaviour {//Use the for initializationvoid Start () {//Destroy objects, Gameobject, visual inspection should refer to the object itself, that is, the need to achieve self-destruction. Destroy (Gameobject, 3.0f);} Update is called once per framevoid update () {}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The code record of the launch ball collision object of Unity Learning note