Create your own awesome maps

Even on the go

with our free apps for iPhone, iPad and Android

Get Started

Already have an account?
Log In

attaching custom script objects by Mind Map: attaching custom script objects
0.0 stars - reviews range from 0 to 5

attaching custom script objects

Using Scripts

writing simple behaviour scripts

JavaScript

C#

Boo

Creating New Scripts

rotate를 위한 Script Component 추가하기

create

main menu, Assets->Create->JavaScript

Project View, NewBehaviourScript

edit

double-clicking on it in the Project View

default script editor, Unity->Preferences->External Script editor

before, function Update () { }

After, function Update () { print("Hello World"); }

Execute

nothing that causes the code to be executed yet

Attaching scripts to objects

Box GameObject 만들어서 추가하기

create a new object

GameObject->Create Other->Cube

2 methods

drag the script from the Project View to the Cube

select the Cube, choose Component->Scripts->New Behaviour Script., Every script you create will appear in the Component->Scripts menu

Inspector

you will see that the script is now visible. This means it has been attached.

Press Play to test your creation.

beside the Play/Pause/Step buttons

Manipulating the GameObject

function Update () { transform.Rotate(0, 5*Time.deltaTime, 0); }

Update () {}, a container for code that Unity executes multiple times per second (once per frame)

transform, a reference to the GameObject’s Transform Component.

Rotate(), a function contained in the Transform Component, The numbers in-between the commas represent the degrees of rotation around each axis of 3D space: X, Y, and Z

Time.deltaTime, a member of the Time class that evens out movement over one second, cube will rotate at the same speed no matter how many frames per second your machine is rendering

The Power of Variables

변수 추가하여 속도 바꾸기 박스 하나 더 추가하여 연결하기

variable can now be modified directly in the Inspector

you can re-use one script on many objects, each with a different variable value.

Accessing Other Components

Using the GameObject members

transform == gameObject.transform

gameObject == this.gameObject

transform.Translate() == gameObject.transform.Translate()

Using GetComponent()

scriptA = GetComponent(“ScriptA”);