• 3D游戏的角色移动


    *   -----英雄的移动控制
     * 
     * 
     * 
     * 
     */
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class HeroMovingControl : MonoBehaviour
    {
        public float FloHeroMovingSpeed = 1F;                  //运动的速度
    
        private CharacterController _ChaHeroControl;           //英雄角色控制器
        private Vector3 _VecHeroMoving;                        //英雄移动
    
    
    	// Use this for initialization
    	void Start () {
            _ChaHeroControl = this.GetComponent<CharacterController>();
    	}
    	
    	// Update is called once per frame
        void Update()
        {
            //英雄的移动
            _VecHeroMoving = Vector3.zero;
            if (Input.GetKey(KeyCode.W))
            {
                _VecHeroMoving.z += FloHeroMovingSpeed * Time.deltaTime;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                _VecHeroMoving.z -= FloHeroMovingSpeed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.A))
            {
                _VecHeroMoving.x -= FloHeroMovingSpeed * Time.deltaTime;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                _VecHeroMoving.x += FloHeroMovingSpeed * Time.deltaTime;
            }
            //Move()方法必须使用世界坐标系
            _ChaHeroControl.Move(this.transform.TransformDirection(_VecHeroMoving));
        }
    }
    

      

  • 相关阅读:
    减治算法之寻找第K小元素问题
    OpenGL的版本号历史和发展
    动态注冊监听
    Thinking in Java -- 类型信息RTTI
    Unity3D
    Oracle改动字段类型
    函数定义
    foreach
    数组
    结构体
  • 原文地址:https://www.cnblogs.com/Optimism/p/9816772.html
Copyright © 2020-2023  润新知