▽メニュー開く 
------EnemyMove.cs 見本---------------------------------
using UnityEngine;
using System.Collections;

public class EnemyMove : MonoBehaviour {

    public enum State {
                Waiting,   //待機
                Walking,    // 探索
                Chasing,    // 追跡
                Attacking,    // 攻撃
                Died,       // 死亡
            };

    GameObject player;
    public float waitingBaseTime    = 2.0f;
    public float walkingBaseTime    = 5.0f;
    public float chasingBaseTime    = 1.0f;
    public float attackingBaseTime    = 1.0f;
    public float shootingBaseTime =2.0f;
    public float dieadBaseTime        = 2.0f;
    public float enemyTime;
    public int walkMuki;
    public State enemyState;
    public GameObject prefab; //プレファブ設定
    private int bulletSpeed=5;

    public int MyHitPoint=20;
    public int MyAttackPoint=1;
    public int MyDiffencePoint =1;

    void Start () {
        enemyTime = waitingBaseTime;
        player = GameObject.Find("Player");
    }



    void Update(){
        enemyTime -= Time.deltaTime;

        switch (enemyState) {
        case State.Waiting:
            Debug.Log ("待ち");
            waiting ();
            break;
        case State.Walking:
            Debug.Log ("歩き");
            walking ();
            break;
        case State.Chasing:
            Debug.Log ("探索");
            chasing ();
            break;
        case State.Attacking:
            Debug.Log ("攻撃");
            attacking ();
            break;
        case State.Died:
            Debug.Log ("死");
            died ();
            break;
        }
            
    }

    void waiting(){
        if(enemyTime<=0){
            enemyTime = chasingBaseTime;
            enemyState = State.Chasing;
        }

    }

    void walking(){

        if(enemyTime<=0){
            walkMuki = Random.Range(0,5);
            enemyTime = attackingBaseTime;
        }


        switch (walkMuki) {
        case 0://プレイヤーの方へ向く
            Debug.Log ("case 0");
            //transform.LookAt (player.transform.position);
            walkMuki=1;
            break;
        case 1://直進
            Debug.Log ("case 1");
            GetComponent ().velocity = transform.forward*3;//向いている方へ 前に進む
            break;
        case 2://正面右30度へ向く
            Debug.Log ("case 2");
            //現在の向いている角度を取得してそれを元に回転する。
            transform.Rotate(0,30,0);//y軸に30度回転
            //transform.rotation = Quaternion.AngleAxis(90, transform.up); 
            transform.forward = transform.TransformDirection(Vector3.forward);//これをつけるとヅレない
            walkMuki=1;
            break;
        case 3://正面左30度へ向く    
            Debug.Log ("case 3");
            transform.Rotate(0,-30,0);//y軸にー30度回転
            //transform.rotation = Quaternion.AngleAxis(-90, transform.up);
            transform.forward = transform.TransformDirection(Vector3.forward);
            walkMuki=1;
            break;
        case 4://あとづさり
            Debug.Log ("case 4");
            GetComponent ().velocity = -transform.forward*3;//後ずさり
            //transform.forward = transform.TransformDirection(-transform.forward);
            //walkMuki=1;
            break;
        case 5://後ろへ進む
            Debug.Log ("case 5");
            transform.Rotate(0,180,0);//y軸に180度回転
            transform.forward = transform.TransformDirection(Vector3.forward);
            walkMuki=1;
            break;
        }


    }

    void chasing(){
        transform.LookAt (player.transform.position);
        enemyTime = walkingBaseTime;
        enemyState = State.Walking;
    }

    void attacking(){
        transform.LookAt (player.transform.position);

    }
    void died(){}




------EnemyMove.cs---------------------------------

戻る

運営者画像
Reon Viewin