【总结】 综合案例FPS3d射击游戏制作

业务需求

综合案例 FPS3d 射击游戏制作
1. 实现控制物体移动旋转方向
WASD 控制物体前后左右移动
ASD 第一按下可以实现转 方向
人物跟随随着鼠标可以左右上下旋转视角
2. 实现摄像机第三人称视角跟踪
3. 实现向屏幕中间发射射线(播放子弹特效、声音)
4. 实现射线射中物体销毁敌人
5. 实现自动刷怪物 ( 间隔 20 ) ,自动销毁怪物( 60 秒)
6. 实现射中物体加分

脚本1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ControlMove : MonoBehaviour
{
    //用户按下WASD控制物体往前后左右移动

    public float MoveSpeed = 10f;

    void Update()
    {

     float MoveLeftR = Input.GetAxis("Horizontal");//当用户按下AD返回1-1
     float MoveFB = Input.GetAxis("Vertical");
     this.transform.Translate(new Vector3(MoveLeftR * 1, 0, 1 * MoveFB) * MoveSpeed * Time.deltaTime);

    }
}//end class

摄像机脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowOBJ : MonoBehaviour
{
    //业务逻辑:这个脚本用来控制摄像机跟踪一个目标
    /*程序逻辑: 1.设置好一个被跟踪的目标 2.我让摄像机的坐标和目标保持同步 3.摄像机得看向目标点  */

    GameObject FollTarget;
    GameObject Looktarget;
    Vector3 speed = Vector3.zero;
    public float FollowTime = 10f;
    void Start()
    {
        FollTarget = GameObject.Find("CameraTarget");//拿到目标点
        Looktarget= GameObject.Find("GameObject");//拿到目标点
    }

    // Update is called once per frame
    void Update()
    {


        this.transform.position = Vector3.SmoothDamp(this.transform.position, FollTarget.transform.position, ref speed, FollowTime);
        
        this.transform.LookAt(Looktarget.transform);

    }
}//end class

 

你可能感兴趣的:(Unity零基础课程,游戏,unity)