2014年1月5日日曜日

unityをまたいじっている

試作追いかけシステム

馬車を剣士が追いかける。

ドラッグドロップで場所移動



このなんか良く分からんスクリプト間の値のやり取りのやり方をうまい事理解できると結構簡単。

using UnityEngine;
using System.Collections;

public class follow : MonoBehaviour {
private GameObject leader;
private float follow_speed;

// Use this for initialization
void Start () {
this.leader = GameObject.FindGameObjectWithTag("leader");
follow_speed = (float)this.GetComponent<parsonal_parameter>().walk_speed;
}

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

Vector3 velo = this.leader.transform.position - this.transform.position;

if(Vector3.Distance(this.leader.transform.position,this.transform.position) > 1.0f){
this.rigidbody.velocity = velo.normalized * follow_speed;
}else{
this.rigidbody.velocity = Vector3.zero;
}
//this.rigidbody.velocity = velo.normalized * 2.0f;

}
}

追いかけるところ。
this.leader = GameObject.FindGameObjectWithTag("leader");
ここと
follow_speed = (float)this.GetComponent<parsonal_parameter>().walk_speed;
ここがめんどっちい。
なんか特殊な関数使ってゲーム内のオブジェクトを区別して値を呼び出してるっていうイメージ。



using UnityEngine;
using System.Collections;

public class parsonal_parameter : MonoBehaviour {

public double walk_speed;

// Use this for initialization
void Start () {

}

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

}
}

キャラの持ってる数値。
まだ速度だけ。