1 / 67

Basic Unity Scripting/Programming & Components

Basic Unity Scripting/Programming & Components. Scripting/programming. Scripting Overview. Scripting inside Unity consists of attaching custom script objects called behaviors to game objects. In C#, subclass MonoBehaviour (note spelling) to implement behaviors.

brinly
Download Presentation

Basic Unity Scripting/Programming & Components

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. Basic Unity Scripting/Programming & Components

  2. Scripting/programming

  3. Scripting Overview • Scripting inside Unity consists of attaching custom script objects called behaviors to game objects. • In C#, subclass MonoBehaviour (note spelling) to implement behaviors. • Different functions inside the script objects are called for certain events.

  4. Scripting Overview • Scripting inside Unity consists of attaching custom script objects called behaviors to game objects. • To make this association, simply drag the script from the Project window to the object in the Hierarchy window. (If a dialog appears that says “Losing prefab” then choose “continue.”)

  5. Scripting Overview • Different functions inside the script objects are called on certain events. • Most frequently used (overridden): void Update ( ) • This function is called before rendering a frame. This is where most game behavior code goes, except physics code. void FixedUpdate ( ) • This function is called once for every physics time step. This is the place to do physics-based game behavior. You can also define (override) event handlers. These all have names starting with On, (i.e. OnCollisionEnter). See MonoBehaviour class documentation.

  6. Basic C# Script NewBehaviourScript is a subclass of MonoBehaviour. using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start ( ) { } // Update is called once per frame void Update ( ) { } } Class name, NewBehaviourScript, must match file name, NewBehaviourScript.cs.

  7. Don’t use ctors! • “Using the constructor when the class inherits from MonoBehaviour, will make the constructor to be called at unwanted times and in many cases might cause Unity to crash.” • http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html

  8. Basic C# Script using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { public Vector3 something; // Use this for initialization void Start ( ) { } // Update is called once per frame void Update ( ) { } } Public member variables will appear in the Unity UI (once an associate between the script and an object has been made). Private, protected, and public const do not.

  9. Components(http://unity3d.com/support/documentation/Components/index.html)Components(http://unity3d.com/support/documentation/Components/index.html)

  10. Unity Components • Animation components • Asset components • Audio components • Physics components • The GameObject • Image effect scripts • Settings managers • Mesh components • Network group • Particle components • Rendering components • Transform component • UnityGUI group • Wizards

  11. Animation Components • Animation • Animation Clip • stores all animation data that can be used for animated characters or simple animations

  12. Asset Components • Assets are the models, textures, sounds and all other “content” files from which you make your game. • Audio Clip • Cubemap Texture • Flare • Font • Material • Meshes • Movie Texture • Render Texture • Text Asset • Texture 2D

  13. Audio Components • These Components implement sound in Unity. • Audio Listener • Add this to a Camera to get 3D positional sound. • Audio Source • Add this Component to a GameObject to make it play a sound. • Audio Effects (PRO only)

  14. Physics Components • Box Collider • Capsule Collider • Character Controller • Character Joint • Configurable Joint • Constant Force • Fixed Joint • Hinge Joint • Mesh Collider • Physic Material • Rigidbody • Sphere Collider • Spring Joint • Interactive Cloth • Skinned Cloth • Wheel Collider

  15. Physics Components • Unity uses the PhysX engine from nvidia. See http://www.nvidia.com/object/physx_new.html for demos, and http://developer.nvidia.com/object/physx.html for developers info.

  16. The GameObject • GameObjects are containers for all other Components. • All objects in your game are inherently GameObjects. • GameObjects do not add any characteristics to the game by themselves. • They are containers that hold Components, which implement actual functionality. For example, a Light is a Component which is attached to a GameObject. an empty game object

  17. Image Effect Scripts • This group handles all Render Texture-based fullscreen image postprocessing effects. • They add a lot to the look and feel of your game without spending much time on artwork. • But they are only available with Unity Pro!

  18. Image Effect Scripts • Blur image effect • Bloom and flares image effect • Color correction curves image effect • Color correction image effect • Contrast enhance image effect • Contrast stretch image effect • Crease image effect • Depth of field image effect • Edge blur image effect • Edge detection image effect • Edge detect normals image effect • Fisheye image effect • Glow image effect • Grayscale image effect • Motion blur image effect • Noise image effect • Sepia tone image effect • Screen Space Ambient Occlusion (SSAO) image effect • Sun shafts image effect • Twirl image effect • Vignetting image Effect • Vortex image effect

  19. Settings Managers • Audio Manager • Input Manager • Network Manager • Physics Manager • Player Settings • Quality Settings • Render Settings • Tag Manager • Time Manager Most can be accessed via Edit  Project Settings  <manager>.

  20. Settings Managers • Audio Manager

  21. Settings Managers • Input Manager

  22. Settings Managers • Network Manager

  23. Settings Managers • Physics Manager

  24. Settings Managers • Player Settings • Player Settings is where you define various parameters (platform specific) for the final game that you will build in Unity.

  25. Settings Managers • Quality Settings

  26. Settings Managers • Render Settings • fog off (right), and fog on (below)

  27. Settings Managers • Tag Manager • The Tag Manager allows you to set up Layers and Tags (Edit->Project Settings->Tags). • Tags are used to quickly find objects from scripts, utilizing the Tag name. • Layers can be used to cast rays, render, or apply lighting to certain groups of objects only.

  28. Settings Managers • Time Manager • Fixed Timestep • A framerate-independent interval that dictates when physics calculations and FixedUpdate() events are performed. • Maximum Allowed Timestep • A framerate-independent interval that caps the worst case scenario when frame-rate is low. Physics calculations and FixedUpdate() events will not be performed for longer time than specified. • Time Scale • The speed at which time progress. Change this value to simulate bullet-time effects. A value of 1 means real-time. A value of .5 means half speed; a value of 2 is double speed.

  29. (End settings managers – back to components)

  30. Mesh Components 3D Meshes are the main graphics primitive of Unity. Various components exist in Unity to render regular or skinned meshes, trails or 3D lines. • Mesh Filter • Mesh Renderer • Skinned Mesh Renderer • Text Mesh

  31. Network Group • Network View • Network Views are the gateway to creating networked multiplayer games in Unity. • They are simple to use, but they are extremely powerful. • You can learn and discover the fundamental concepts in the Network Reference Guide.

  32. Particle Components • Particle Systems are used to make clouds of smoke, steam, fire and other atmospheric effects. • Particle systems in Unity work by using one or two textures, and drawing them many times, creating a chaotic effect. • They are 2D in Unity.

  33. Particle Components • Ellipsoid Particle Emitter • Line Renderer • Mesh Particle Emitter • Particle Animator • Particle Renderer • Trail Renderer • Particle Collider

  34. Particle Components • Ellipsoid Particle Emitter • The Ellipsoid Particle Emitter spawns particles inside a sphere. • Use the Ellipsoid property below to scale & stretch the sphere.

  35. Particle Components • Line Renderer • The Line Renderer takes an array of two or more points in 3D space and draws a straight line between each one. A single Line Renderer Component can thus be used to draw anything from a simple straight line, to a complex spiral. The line is always continuous; if you need to draw two or more completely separate lines, you should use multiple GameObjects, each with its own Line Renderer. • The Line Renderer does not render one pixel thin lines. It renders billboard lines that have width and can be textured. It uses the same algorithm for line rendering as the Trail Renderer.

  36. Particle Components • Mesh Particle Emitter • The Mesh Particle Emitter emits particles around a mesh. Particles are spawned from the surface of the mesh, which can be necessary when you want to make your particles interact in a complex way with objects.

  37. Particle Components • Particle Animator • Particle Animators move your particles over time, you use them to apply wind, drag & color cycling to your particle systems.

  38. Particle Components • Particle Renderer • The Particle Renderer renders the Particle System on screen.

  39. Particle Components • Trail Renderer • The Trail Renderer is used to make trails behind objects in the scene as they move about.

  40. Particle Components • Particle Collider • The World Particle Collider is used to collide particles against other Colliders in the scene.

  41. Particle Components • Once again, they are 2D in Unity. • See http://www.youtube.com/view_play_list?p=55C1A52A917B2DDF for examples of 3D particle systems. • Also see http://software.intel.com/en-us/articles/tickertape/ for Intel’s parallel 3D particle systems (2 videos: demo and discussion).

  42. Rendering Components • This group contains all Components that have to do with rendering in-game and user interface elements. Lighting and special effects are also included in this group. • Camera • Flare Layer • GUI Layer • GUI Text • GUI Texture • Halo • Halo Layer • Lens Flare • Light • Lightmapping • Projector • Skybox

  43. Rendering Components • Camera • Cameras are the devices that capture and display the world to the player. By customizing and manipulating cameras, you can make the presentation of your game truly unique. You can have an unlimited number of cameras in a scene. They can be set to render in any order, at any place on the screen, or only certain parts of the screen.

  44. Rendering Components • Camera • Two-player display created with Normalized Viewport Rectangle

  45. Rendering Components • Camera • perspective (left) and orthographic/parallel (right)

  46. Rendering Components • Camera • Render texture • This feature is only available for Unity Advanced licenses. It will place the camera's view onto a Texture that can then be applied to another object. This makes it easy to create sports arena video monitors, surveillance cameras, reflections etc. • A Render Texture used to create a live arena-cam below.

  47. Rendering Components • Flare Layer • The Flare Layer Component can be attached to Cameras to make Lens Flares appear in the image. • By default, Cameras have a Flare Layer already attached.

  48. Rendering Components • GUI Layer • A GUI Layer Component is attached to a Camera to enable rendering of 2D GUIs. • When a GUI Layer is attached to a Camera it will render all GUI Textures and GUI Texts in the scene. GUI Layers do not affect UnityGUI in any way. • You can enable and disable rendering GUI in a single camera by clicking on the check box of the GUI Layer in the Inspector.

  49. Rendering Components • GUI Text • GUI Text displays text of any font you import in screen coordinates.

More Related