zoukankan      html  css  js  c++  java
  • unity游戏教程 space shooter (销毁)

    为了更好地理解unity,模仿了教程,以下均为教程中的代码:

    DestroyByBoundary:

    using UnityEngine;
    using System.Collections;
    
    public class DestroyByBoundary : MonoBehaviour
    {
    	void OnTriggerExit (Collider other) 
    	{
    		Destroy(other.gameObject);
    	}
    }
    

    DestroyByContact.cs:

    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DestroyByContact : MonoBehaviour {
    
    	public GameObject explosion;
    	public GameObject playerExpolsion;
    	public int score;
    	private GameController gameController;
    
    	void Start(){
    		GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    		if(gameControllerObject != null){
    			gameController = gameControllerObject.GetComponent<GameController> ();
    		}
    		if(gameControllerObject == null){
    			Debug.Log("can not find 'GameController'script");
    		}
    	}
    
    
    
    	void OnTriggerEnter(Collider other){
    
    		if(other.tag=="Boundary"){
    			return;
    		}
    
    		Instantiate (explosion, transform.position, transform.rotation);
    
    		if(other.tag=="Player"){
    			Instantiate (playerExpolsion,other.transform.position,other.transform.rotation);
    			gameController.GameOver ();
    		}
    
    		gameController.addScore (score);
    		Destroy (other.gameObject);
    		Destroy (gameObject);
    
    	}
    }
    

    DestroyByBoundary:

    using UnityEngine;
    using System.Collections;
    
    public class DestroyByBoundary : MonoBehaviour
    {
    	void OnTriggerExit (Collider other) 
    	{
    		Destroy(other.gameObject);
    	}
    }
    

    DestroyByContact.cs:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DestroyByContact : MonoBehaviour {
    
    	public GameObject explosion;
    	public GameObject playerExpolsion;
    	public int score;
    	private GameController gameController;
    
    	void Start(){
    		GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    		if(gameControllerObject != null){
    			gameController = gameControllerObject.GetComponent<GameController> ();
    		}
    		if(gameControllerObject == null){
    			Debug.Log("can not find 'GameController'script");
    		}
    	}
    
    
    
    	void OnTriggerEnter(Collider other){
    
    		if(other.tag=="Boundary"){
    			return;
    		}
    
    		Instantiate (explosion, transform.position, transform.rotation);
    
    		if(other.tag=="Player"){
    			Instantiate (playerExpolsion,other.transform.position,other.transform.rotation);
    			gameController.GameOver ();
    		}
    
    		gameController.addScore (score);
    		Destroy (other.gameObject);
    		Destroy (gameObject);
    
    	}
    }
    

    DestroyByTime .cs:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DestroyByTime : MonoBehaviour {
    
    	public float lifeTime;
    
    	// Use this for initialization
    	void Start () {
    		Destroy (gameObject,lifeTime);
    	}
    	
    	// Update is called once per frame
    	void Update () {
    		
    	}
    }
    
  • 相关阅读:
    2020面试阿里,字节跳动90%被问到的JVM面试题
    mysql数据库误删恢复
    因用了Insert into select语句,公司报警了
    Spring的Controller是单例还是多例?怎么保证并发的安全
    SpringBoot项目优化和Jvm调优
    java从一个pdf中取出指定页生成一个新的pdf
    java截取出字符串中的所有组数字
    oracle表空间位置迁移
    solr常用操作及集成分词器或cdh集群部署说明
    Oracle中将列查询结果多行逗号拼接成一个大字段
  • 原文地址:https://www.cnblogs.com/1997Ff/p/7364702.html
Copyright © 2011-2022 走看看