using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { private const string MAIN_CAMERA_TAG_NAME = "MainCamera";//メインカメラのタグ名 private bool Rendered = false;//カメラに映っているか判定する変数 // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Rendered == true)//もしRenderedがtrueなら、 { transform.position += new Vector3(-10 * Time.deltaTime, 0, 0);//x座標を-10ずつ変える } } void OnWillRenderObject()//カメラに映ってる間に呼ばれ続ける処理 { if (Camera.current.tag == MAIN_CAMERA_TAG_NAME)//もしメインカメラに映ったら、 { Rendered = true;//Renderedをtrueにする } } }
これで、カメラに映るまで敵は動かず、カメラに映ったら動くようになります
コメント