Unity forge
Overview: Common Operations Manual     Reference     Scripting  
Scripting
Overview: Common Operations
  • Menu
  • Overview
  • Runtime Classes
  • Attributes
  • Enumerations
  • Editor Classes
  • Enumerations
  • History
  • Index
  • Scripting Overview
  • Common Operations
  • Time
  • Accessing Components
  • Accessing Objects
  • Vectors
  • Variables
  • Instantiate
  • Coroutines & Yield
  • Using C#
  • Important Classes
  • Performance Optimization
  • Script Compilation
  • Unity and Mono compatibility

Most game object manipulations are done either through the game object's Transform and/or Rigidbody. These are accessible inside behaviour scripts through the member variables transform and rigidbody respectively. So if you wanted to rotate an object 5 degrees around its Y axis every frame you could write the following:

JavaScripts
function Update() {
transform.Rotate(0, 5, 0);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void Update() {
transform.Rotate(0, 5, 0);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def Update():
transform.Rotate(0, 5, 0)

If you want to move an object forward you would write this:

JavaScripts
function Update() {
transform.Translate(0, 0, 2);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void Update() {
transform.Translate(0, 0, 2);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def Update():
transform.Translate(0, 0, 2)


Unity3d Рекламный блок Unity3d



Установить Adobe Flash плеер
Ruslan Slobodianiuk © unity3dforge.com все права защищены

Полезные ресурсы:

Программа для создания скриншотов