2014年8月25日 星期一

計時器搭配物件旋轉

Unity Web Player | New Unity Project



製作圖片:

---------------------------------------------------------------------------------

程式部分 :

螺旋槳腳本:

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

public float speed = 0f;

float timer_f;
int timer_i;

// Update is called once per frame
void Update () {

timer_f = Time.time;
timer_i = Mathf.FloorToInt (timer_f);

Debug.Log (timer_i);

if(timer_i != 0){

transform.Rotate(Vector3.up * Time.deltaTime * speed);

speed += 1;

}
if(speed >= 800){
speed = 800;
transform.Rotate(Vector3.up * Time.deltaTime * speed);
}
}

void OnGUI(){
if(GUI.Button(new Rect(Screen.width/Screen.width, Screen.height/Screen.height, 100, 50),"return")){
Application.LoadLevel("AAABBB");
}
}
}

攝影機腳本:

var target : Transform;
var distance = 10.0;

var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = -20;
var yMaxLimit = 80;

private var x = 0.0;
private var y = 0.0;

@script AddComponentMenu("Camera-Control/Mouse Orbit")

function Start () {
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;

// Make the rigid body not change rotation
    if (GetComponent.<Rigidbody>())
GetComponent.<Rigidbody>().freezeRotation = true;
}

function LateUpdate () {
    if (target) {
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 
  y = ClampAngle(y, yMinLimit, yMaxLimit);
        
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;
        transform.position = position;
    }
}

static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}

沒有留言:

張貼留言