码迷,mamicode.com
首页 > 其他好文 > 详细

吃到奖励变换子弹的方法

时间:2016-04-03 22:12:25      阅读:114      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!