Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Last active December 29, 2015 17:38
Show Gist options
  • Save Buravo46/7705034 to your computer and use it in GitHub Desktop.
Save Buravo46/7705034 to your computer and use it in GitHub Desktop.
【Unity】2D用の、ターゲットのx,y座標とカメラのx,y座標を同じ値にするスクリプト。
using UnityEngine;
using System.Collections;
public class CameraChasingTargetScript : MonoBehaviour {
// Target Object
public GameObject targetObject;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// 現在位置をPositionに代入
Vector3 Position = targetObject.transform.position;
// Z軸修正
Position.z = -8;
// 現在の位置に加算減算を行ったPositionを代入する
transform.position = Position;
}
}
#pragma strict
// Target Object
var targetObject:GameObject;
// Use this for initialization
function Start () {
}
// Update is called once per frame
function Update () {
// 現在位置をカメラ座標に代入
transform.position = targetObject.transform.position;
// Z軸修正
transform.position.z = -8;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment