吃到奖励变换子弹的方法

Posted 礼桀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了吃到奖励变换子弹的方法相关的知识,希望对你有一定的参考价值。

public class hero : MonoBehaviour
{
    public float superGunTime = 10f;
    private float resetSuperGunTime;
    private int GunCount = 1;

//用fire脚本去声明三个变量来存放三个位置的枪口
public fire upGun; public fire rightGun; public fire leftGun; void Start() { // player = GameObject.FindGameObjectWithTag("Player").transform; resetSuperGunTime = superGunTime; superGunTime = 0; GunCount = 1; upGun.OnFire(); } void Update() { superGunTime -= Time.deltaTime; if (superGunTime > 0) { if (GunCount==1) { GunToSuperGun(); GunCount = 3; } } else { GunToNormal(); GunCount = 1; } } private void GunToSuperGun() { //得到fire脚本的OnFire方法 rightGun.OnFire(); leftGun.OnFire(); } private void GunToNormal() { rightGun.StopFire(); leftGun.StopFire(); } public void OnTriggerEnter2D(Collider2D collider) { if (collider.tag=="Award")//判断是否碰到了Tag标签 { print("是Awar"); Award award = collider.GetComponent<Award>();//得到Award脚本的组件 if (award.type==1)//判断type的类型 { print("是1"); superGunTime = resetSuperGunTime; Destroy(collider.gameObject);//销毁碰撞到的物体的 } } } }

这里是fire脚本的代码

using System;
using UnityEngine;
using System.Collections;

public class fire : MonoBehaviour
{

    public float rate = 0.2f;
    public GameObject bullet;

    
    //实例化子弹
    public void Fire()
    {
        GameObject.Instantiate(bullet, transform.position, Quaternion.identity);
    }
    //如何实例化子弹
    public void OnFire()
    {
        InvokeRepeating("Fire",0.1f,rate);
    }

    //停止子弹发射
    public void StopFire()
    {
        //取消invoke的指令
        CancelInvoke("Fire");
    }
}

 

以上是关于吃到奖励变换子弹的方法的主要内容,如果未能解决你的问题,请参考以下文章

1163 最高的奖励 贪心 + 并查集

2019 春第1次课程设计实验报告

Android 高级UI解密 :PathMeasure截取片段 与 切线(新思路实现轨迹变换)

Android 高级UI解密 :PathMeasure截取片段 与 切线(新思路实现轨迹变换)

Android 高级UI解密 :PathMeasure截取片段 与 切线(新思路实现轨迹变换)

子弹的发射