首页 > 其他 > 详细

吃到奖励变换子弹的方法

时间:2016-04-03 22:10:12      阅读:260      评论:0      收藏:0      [点我收藏+]
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");
    }
}

 

吃到奖励变换子弹的方法

原文:http://www.cnblogs.com/fuperfun/p/5350765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!