zoukankan      html  css  js  c++  java
  • 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));
        }
    }
    

      

  • 相关阅读:
    POJ 3672 水题......
    POJ 3279 枚举?
    STL
    241. Different Ways to Add Parentheses
    282. Expression Add Operators
    169. Majority Element
    Weekly Contest 121
    927. Three Equal Parts
    910. Smallest Range II
    921. Minimum Add to Make Parentheses Valid
  • 原文地址:https://www.cnblogs.com/Optimism/p/9816772.html
Copyright © 2011-2022 走看看