Unity Official tutorial Space shooter study notes

Source: Internet
Author: User

I think this tutorial is the biggest inspiration to me is one of the words, sub-object is a map, the parent object is a property. So we'd better build an empty gameobject before we create the object.

This will not only keep the hierarchy panel neat and manageable, but also realize what you just said. Okay, here's the point.

How do I create a bullet?

We first create a plane, then assign the bullet's map to the plane, and then select the shader option for the mobile particles additive, so that only the laser part can be displayed,

The black part will be hours, and finally the bullet will be added to the Rigidbody component and the capsule collider component, so the bullet is complete.

How do we get the bullets moving?

Just give it a first speed in the direction of the bullet's z-axis.

Using unityengine;using System.collections;public class Boltmove:monobehaviour {public float speed;//with this for Initi Alizationvoid Start () {rigidbody.velocity = Transform.forward * speed;}}

how do you allow bullets to be fired at a certain frequency?

void Update () {//Generate an object in a fixed time period if (Time.time > Nextfire) {nextfire = Time.time + firerate;instantiate (shot, SHOTSPAWN.P Osition, shotspawn.rotation);}}
Shotspwan.position is the location of the ship, Firerate is the frequency we want.

How to limit the movement of the spacecraft to a certain extent?

Here we need to use the clamp in a function mathf

Using unityengine;using System.Collections; [System.serializable]public class Limit{public float xmax,xmin,zmax,zmin;} public class Playrcontrol:monobehaviour {public float speed;public Limit limit;public float tilt;public gameobject shot; Public Transform shotspawn;void fixedupdate () {Float x = Input.getaxis ("horizontal"); Float y = Input.getaxis ("Vertical") ; Vector3 movement = new Vector3 (x, 0.0f, y); rigidbody.velocity = Movement * speed;rigidbody.position = new Vector3 (MATHF.C Lamp (rigidbody.position.x, Limit.xmin, Limit.xmax), 0.0f,mathf.clamp (Rigidbody.position.z, Limit.zMin, Limit.zMax)) ; rigidbody.rotation = Quaternion.euler (0.0f, 0.0f, rigidbody.velocity.x *-tilt);}}
How can bullets and meteorites be destroyed when they fly out of the border?

Here we need a big cube to surround our game scene, then add a box collider component to cube and then detect if an object leaves the trigger and destroys it.

void Ontriggerexit (Collider other) {Destroy (other.gameobject);}

How can a bullet collide with a meteorite or a spaceship collide with a meteorite, destroying it at the same time and producing an explosive effect?

void Ontriggerenter (Collider other) {if (Other.tag = = "Boundary") return;hard++;if (hard = = 2) {Instantiate (explosion, oth Er.transform.position, Other.transform.rotation);D Estroy (gameobject); Gamecontrol.addscore (Scorevalue);} if (Other.tag = = "Player") {Instantiate (Player_explosion, Other.transform.position, other.transform.rotation);D Estroy (gameobject); gamecontrol.gameover = true;} Debug.Log (other.name);D Estroy (other.gameobject);}
Let me explain.
if (Other.tag = = "Boundary")
Because this function is executed when the trigger is entered, our meteorite is always in the cube's trigger, so we want to rule out cube interference.

Instantiate (explosion, other.transform.position, other.transform.rotation);
This is the result of an exploding object in the current position of the bullet.


Like He Ibo's spawn enemies?

void Start () {Startcoroutine (spawnwaves ());} IEnumerator spawnwaves () {while (true) {yield return new waitforseconds (startwait), for (int i = 0; i < Hazardcount; i++ {Vector3 Spawnpositoin = new Vector3 (Random.range (-spawnvalues.x-3, spawnvalues.x-3), 0, spawnvalues.z); quaternion spawnrotation = quaternion.identity;instantiate (Hazard, Spawnpositoin, spawnrotation); yield return new Waitforseconds (spawnwait);}}}




Unity Official tutorial Space shooter study notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.