1 / 11

Learning Unity

Learning Unity. A Simple Game. Just by adding in a few platforms, we can make a game. Try to get from the left platform to the right one. Prefabs. A Prefab is a tool for combining objects together. First create an object Created a sphere with a sphere above and below (all attached together)

iram
Download Presentation

Learning Unity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Learning Unity

  2. A Simple Game • Just by adding in a few platforms, we can make a game. • Try to get from the left platform to the right one.

  3. Prefabs • A Prefab is a tool for combining objects together. • First create an object • Created a sphere with a sphere above and below (all attached together) • Create Prefab • Drag into Prefab

  4. Create the Prefab • First delete the original instance • Create new script • Instantiate to create object. Creates on top of script object • Add script to actor • Link object to prefab

  5. Prefabs Extended • Prefabs also carry any scripts that were attached to them • You can modify Prefabs by first instantiating them • Drag to the main screen • Then editing them • Then dragging back to the prefab • Add a RididBody • Modify code • Instantiate(object, transform.position + Vector3(0,0,2), transform.rotation) ; • Now object appears in front of you.

  6. Responding to Mouse • Mouse Click • Type 1: Input.GetMouseButtonDown(button) • Test is button has been pressed • Type 2: function OnMouseDown() {} • Called when this object is clicked on • Now create instance when you click

  7. Responding to Key • Input.GetKeyDown(key) • Returns true if key was just pressed • If – else if • Only test the “else if” condition if the “if” condition fails • Comments • Human only • Not read by computer

  8. Forces • To apply a force to an object • First, extract the Rigidbody component • Second, set the velocity on that component • Optional: AddForce – allows you to apply a constant force on the object • Also, instantiation modification • Position at transform.rotation * Vector3(0,0,2) • This will place the object in front of where you are currently looking

  9. Removing an Object • Create new Script (Name: DestroyOnClick) • Attach to the prefab • Call the Destroy method • Can be used on the • gameObject • Removes the whole thing • Transform • ERROR: do not do • this • Destroy the script itself • Any other script

  10. Global variables • Static keyword • Create variable that anyone can access • Not specific to an instance • Tracks how many objects have been clicked on

  11. Showing score • Create new GUIText • GameObject -> Create Other -> GUI Text • Place so you can see in world • Will stay static in position with reference to you • Attach a script to it (name: UpdateScore) • Every tick, update score to reflect number clicked

More Related