首页 > 其他分享 >unity3D设置手枪的动画与子弹的自动销毁07

unity3D设置手枪的动画与子弹的自动销毁07

时间:2023-03-04 17:55:33浏览次数:47  
标签:unity3D float 07 shootTimer 动画 子弹 private using maxXRotation

取消手枪自动播放动画

image

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

public class GunManager : MonoBehaviour
{
    //1.枪旋转角度 xy轴轩轩角度
    private float maxYRotation = 120;
    private float minYRotation = 0;
    private float maxXRotation = 60;
    private float minXRotation = 0;

    //2.枪射击时间 射击间隔时长
    private float shootTime = 1;
    private float shootTimer = 0;

    //7.得到子弹物体和位置信息
    public GameObject bulletGO;
    public Transform firePosition;

    //3.更新
    private void Update()
    {
        shootTimer += Time.deltaTime;
        if (shootTimer > shootTime)
        {
            //8.点击鼠标左键进行射击
            if (Input.GetMouseButtonDown(0))
            {
                //9.实例化子弹
                GameObject bulletCurrent = GameObject.Instantiate(bulletGO, firePosition.position, Quaternion.identity);
                //11.获得子弹后 通过刚体组件给子弹添加一个正前方向上的力,以达到让子弹向前运动的效果
                bulletCurrent.GetComponent<Rigidbody>().AddForce(transform.forward * 2000);

                //12.获得组件后做操作
                gameObject.GetComponent<Animation>().Play();
                //10.计时器归零 每1秒生成一次
                shootTimer = 0;
            }
        }

        //4.旋转 获取鼠标坐标
        float xPosPrecent = Input.mousePosition.x / Screen.width;
        float yPosPrecent = Input.mousePosition.y / Screen.height;

        //5.规定旋转角度最大最小值范围
        float xAngle = -Mathf.Clamp(yPosPrecent * maxXRotation, minXRotation, maxXRotation) + 15;
        float yAngle = Mathf.Clamp(xPosPrecent * maxYRotation, minYRotation, maxYRotation) - 60;

        //6.赋值给枪的组件值
        transform.eulerAngles = new Vector3(xAngle, yAngle, 0);
    }

}

设置子弹自动销毁

不管有没有打到怪物,一定时间子弹消失

新建脚本文档

image

显示bullet apply

image

image

标签:unity3D,float,07,shootTimer,动画,子弹,private,using,maxXRotation
From: https://www.cnblogs.com/flyall/p/17178687.html

相关文章

  • 07:swift-闭包
    复习 正文/*7:闭包1:**闭包能够捕获和存储定义在其上下文中的任何常量和变量的引用,这也就是所谓的闭合并包裹那些常量和变量,因此被称为“闭包”.Swif......
  • HDOJ 2061-2070
    2061Treasurethenewstart,freshmen!ProblemDescriptionbackground:Anewsemestercomes,andtheHDUalsomeetsits50thbirthday.Nomatterwhat'syou......
  • 题解 P3455 [POI2007]ZAP-Queries
    题目link是莫比乌斯函数还是莫比乌斯反演捏?感觉好多所谓“莫比乌斯反演”题只要拿\(\mu\)性质给暴力替换一下就能做出来了,比如这题qwq答案是这个式子:\(\sum\limits_{......
  • unity3D控制手枪的旋转05
    新建脚本文档要达到鼠标控制手枪的旋转确定枪的旋转角度usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassGunManage......
  • SQLSTATE[22007]:无效的日期时间格式:1366不正确的整数值:
    前言这几天在爬取html时出现了这个问题才发现有emoj表情存在,这个之前在做小程序时遇到过,许多微信名称都会有emoj的存在,所以微信授权都拿不到。查看错误代码之后发现是同样......
  • unity3D使用协程控制怪物的生命周期
    分析九个坑位要随机生成怪物,随机时间生成类似打地鼠协程(Coroutines)协程:协程是一个分部执行,遇到条件(yieldreturn语句)时会挂起,直到条件满足时才会被唤醒继续执行后面的......
  • unity3D控制怪物的随机生成
    对target创建脚本逻辑梳理控制目标显示与隐藏控制被射击是否显示死亡动画创建怪物数组usingSystem.Collections;usingSystem.Collections.Generic;usingUni......
  • 路飞项目day_07
    目录今日内容详细一、为开源项目贡献代码二、pycharm使用git三、登录注册功能分析四、手机号是否存在视图函数模板五、多方式登录接口1.视图类2.序列化类六、腾讯云短信申......
  • 路飞项目---day07()
    昨日回顾#GIt内容大回顾#1版本管理软件:git,svn -代码合并-代码版本管理-协同开发,合并代码#2git跟svn区别#3git安装:相应平台软件,下载完成,一路下......
  • 代码随想录算法训练营第四天 | 24. 两两交换链表中的节点、19.删除链表的倒数第N个节
    24.两两交换链表中的节点-力扣(LeetCode)给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交......