zoukankan      html  css  js  c++  java
  • Unity3D 3D坦克大战

     视频学习来源

    移动和旋转

    using UnityEngine;
    using System.Collections;
    /*
     * Adminer:sun2955
     * http:www.yinghy.com
     * */
    public class Move : MonoBehaviour {
        private float moveSpeed = 7;
        private float rotateSpeed = 150;
        
        // 使用进行初始化
        void Start () {
        
        }
        
        //每一帧都会调用该函数
        void Update () {
    
     
           //  float inputx = Input.GetAxis("Horizontal"); //获得水平移动
           // float inputy = Input.GetAxis("Vertical"); //获得垂直移动
    
           //// this.transform.Translate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
    
           // if(Input.GetKey(KeyCode.A)){
           //     this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
           // }
           // if (Input.GetKey(KeyCode.D))
           // {
           //     this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
           // }
        if(Input.GetKey(KeyCode.W)){
            this.transform.Translate(new Vector3(1, 0, 0)* moveSpeed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.S))
        {
            this.transform.Translate(new Vector3(1, 0, 0) * -moveSpeed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.A))
        {
            this.transform.Rotate(new Vector3(0, 1, 0) * -rotateSpeed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.D))
        {
            this.transform.Rotate(new Vector3(0, 1, 0) *  rotateSpeed * Time.deltaTime);
        }
       
        }
        //物理运动
        void FixedUpdate() 
        {
    
        }
    }

     相机的跟随移动

    基本思路:主相机设定为一个比较好的视角,然后让相机以该视角的相对距离一直跟谁着移动。

    实现思路:设定好相机的左边后,建立一个空物体,将相机挂在空物体的下面,空物体的左边是跟谁主角色进行变化,这样就能实现主角动,相机动,并且相机以一定的相对距离拍摄主角

    using UnityEngine;
    using System.Collections;
    
    public class CameraMove : MonoBehaviour {
        private Transform tanktransform;
        // Use this for initialization
        void Start () {
            tanktransform = GameObject.FindGameObjectWithTag("Player").transform;
        }
        
        // Update is called once per frame
        void LateUpdate () {
            this.transform.position = tanktransform.position;
        }
    }
  • 相关阅读:
    (剑指Offer)面试题18:树的子结构
    (剑指Offer)面试题17:合并两个排序的链表
    (剑指Offer)面试题16:反转链表
    程序员水平分级 你属于哪一类?
    Hacker
    十分钟让你看懂中国经济形势,10分钟,坚持看完,必有所获~(转载)
    人口问题,怎样的生育率才能保持正常的世代更替?
    理科和文科的区别?
    柴晓霞:做销售要学会画蓝图 (转载)
    工作,为钱还是为理想
  • 原文地址:https://www.cnblogs.com/sunxun/p/5463454.html
Copyright © 2011-2022 走看看