最近做战斗逻辑的时候发现一个问题

测试脚本mTest:

public class mTest : MonoBehaviour
{
public mTest2 tmp2; void OnGUI()
{
if (GUI.Button(new Rect(10, 150, 150, 100), "first click"))
{
Destroy(tmp2);
} if (GUI.Button(new Rect(10, 10, 150, 100), "second click after first click some seconds"))
{
Debug.Log(" tmp2 == null : " + (tmp2 == null)); ///output : true Debug.Log(tmp2.value); tmp2.Test();
///output : test ///why !? Debug.Log(tmp2.name);
///output : MissingReferenceException: The object of type 'mTest2' has been destroyed but you are still trying to access it.
///Your script should either check if it is null or you should not destroy the object.
}
} }

测试脚本mTest2:

public class mTest2 : MonoBehaviour
{
public string value = "11";
public void Test() { Debug.Log("test"); }
}

奇怪的问题,如下解决:

 if (GUI.Button(new Rect(10, 150, 150, 100), "first click"))
{
Destroy(tmp2);
tmp2 = null;
}

完全百思不得其解,已经是Null了,为什么还能调用其方法呢?u3d的bug吧,估计。

所以以后我们要引用一个物体,销毁是我们调用的,那么最好设置一下引用为null。

Destroy reall destroy ?!的更多相关文章

  1. angular destroy & jquery destroy

    destroy的目的是为了内存溢漏,这对性能会造成影响. angular scope在处理element 移除时,会触发destroy, 而调用逻辑和jquery使用的一样. 在ck editor 中 ...

  2. unity, destroy gameObject & destroy all children

    一,destroy gameObject 删除名为xxx的gameObject 错误方法1: Destroy(xxx); 以上方法之所以错误,是因为Destroy在下一帧才生效,而在本帧之内xxx还存 ...

  3. dojo.create\dojo.place\dojo.empty\dojo.destroy\dojo.body

    1.dojo.create 1.create a node; 2.set attributes on it;  3.place it in the DOM. dojo.create(/*String| ...

  4. Vue.extend构造器和$mount实例构造组件后可以用$destroy()进行卸载,$forceUpdate()进行更新,$nextTick()数据修改

    html <div id="app"> </div> <p><button onclick="destroy()"&g ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(81)-数据筛选(万能查询)

    系列目录 前言 听标题的名字似乎是一个非常牛X复杂的功能,但是实际上它确实是非常复杂的,我们本节将演示如何实现对数据,进行组合查询(数据筛选) 我们都知道Excel中是如何筛选数据的.就像下面一样 他 ...

  6. [Servlet] 初识Servlet

    什么是Servlet? 定义 Servlet的全称是 Server Applet,顾名思义,就是用 Java 编写的服务器端程序. Servlet 是一个 Java Web开发标准,狭义的Servle ...

  7. 使用Servlet和JSP实现一个简单的Web聊天室系统

    1 问题描述                                                利用Java EE相关技术实现一个简单的Web聊天室系统,具体要求如下. (1)编写一个登录 ...

  8. Servlet的生命周期

    Servlet的生命周期 Servlet的生命周期是由tomcat服务器来控制的. 1 构造方法: 创建servlet对象的时候调用.默认情况下,第一访问servlet就会创建servlet对象只创建 ...

  9. javaWeb实现登录功能

    1.三要素 (1) 入口 就是我们所在的页面 入口到处理的数据请求会出现乱码,用request.SetCharacterEncoding("UTF-8");来解决,仅仅是用用于Po ...

随机推荐

  1. WCF测试小程序

    using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;u ...

  2. 怎样简单编写一个html网页

    # 转载请留言联系 一个HTML的基本结构如下: <!DOCTYPE html> <html lang="en"> <head> <met ...

  3. 分析函数调用堆栈的原理和Delphi实现

    来自:http://blog.163.com/liuguang_123/blog/static/816701920105262543890/ ----------------------------- ...

  4. redis SCAN cursor

    https://redis.io/commands/scan 可以看到: sscan的返回结果,有两部分, 第一部分  是一个数字.其实代表一个游标. 第二部分  是结果. scan是以游标为基础,每 ...

  5. k8s的chart学习(上)

    chart 是 Helm 的应用打包格式.chart 由一系列文件组成,这些文件描述了 Kubernetes 部署应用时所需要的资源,比如 Service.Deployment.PersistentV ...

  6. 第一篇:动态防火墙firewalld和静态防火墙iptables

    动态防火墙firewalld firewalld提供了一个动态管理的防火墙,它支持网络(network)/防火墙区域(firewall zones )来定义网络连接( network connecti ...

  7. django + dropzone.js 上传文件

    1.dropzone.js http://www.dropzonejs.com/ dropzone.js是一个可预览\可定制化的文件拖拽上传,实现AJAX异步上传文件的工具 2.dropzone.js ...

  8. CF 1003D Coins and Queries【位运算/硬币值都为2的幂/贪心】

    Polycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are int ...

  9. HDU 2503 (数论,最大公约数)

    a/b + c/d Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  10. Codeforces Round 254 (Div. 2)

    layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...