一、游戏要求
8b0c48bd91810d719d86368d7817877.png

二、游戏玩法
1、按Tab键切换天空盒
2、按方向键或者WASD控制人物移动,空格键跳跃
3、鼠标左键按下蓄力,松开释放弓箭

三、游戏演示
1、视频演示
2、代码

四、实现思路
1、天空盒切换

using UnityEngine;

public class SkyboxSwitcher : MonoBehaviour
{
    // 在Inspector窗口中分配不同的天空盒材质
    public Material skybox1;
    public Material skybox2;

    // 设置一个按键来切换天空盒,空格键
    public KeyCode switchKey = KeyCode.Space;

    // 用一个布尔值来记录当前使用的天空盒
    private bool usingSkybox1 = true;

    // 在每一帧中,检测按键输入
    void Update()
    {
        // 如果按下了切换键
        if (Input.GetKeyDown(switchKey))
        {
            // 如果当前使用的是天空盒1,就切换到天空盒2,反之亦然
            if (usingSkybox1)
            {
                RenderSettings.skybox = skybox2;
                usingSkybox1 = false;
            }
            else
            {
                RenderSettings.skybox = skybox1;
                usingSkybox1 = true;
            }
        }
    }
}

2、人物移动
把crossbow放入fpscontroller的子对象里
44975fdc65191b31d28a6101a9586ba.png

3、蓄力动画
animator:
d1584640b9f7e1b4a692cb298744479.png

Fill的混合树:
1ef6196a260bdf07c378a2395cbd6c9.png

Shoot的混合树:
31813c4ec83d9f91b472cc74758a4a2.png
4、固定靶和运动靶
靶子都要添加碰撞盒:Component->Physics->Box Collider
157bb28e0cb6b5ca1f92ca7c587e00e.png

5、射击位

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

public class standplace : MonoBehaviour
{
    //射击位被激活和未激活的材质,分别为白色和红色
    private Material active;
    private Material unactive;

    //修改材质用
    private Renderer ren;
    // Start is called before the first frame update
    void Start()
    {
        // sc = Singleton<SceneController>.Instance;
        active = Instantiate(Resources.Load<Material>("Material/active"));
        unactive = Instantiate(Resources.Load<Material>("Material/unactive"));
        ren = GetComponent<Renderer>();
        ren.material = unactive;
    }

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

    //检测Player进入射击位
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            ren.material = active;
        }
    }

    //检测Player离开射击位
    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
             ren.material = unactive;
        }
    }
}

Kim_Yang
1 声望1 粉丝