废话不多说,直接上代码
//表示需要进行补丁的成员 [HarmonyPatch(typeof(Vehicle), nameof(Vehicle.Update))] public class Vehicle_Update_Patch { //HarmonyPostfix表示在目标成员代码尾行进行代码补丁/追加,且HarmonyPostfix特性需要标记在一个静态方法上面 [HarmonyPostfix] //此处被HarmonyPostfix特性标记的方法的形参 Vehicle __instance 表示获取目标成员所属类的实例对象Vehicle public static void AddPostfix(Vehicle __instance) {() //IsDriven函数用于判断是否处于驾驶状态 if (__instance.entity.IsDriven()) { //获取当前载具的位置,类型为Vector3 Vector3 pos = __instance.entity.position; //WaterDragY字段表示当前载具离水面的距离,所以pos.y += __instance.WaterDragY 之后的坐标值就是当前载具的车顶 pos.y += __instance.WaterDragY; //首先World.worldToBlockPos函数可以将Unity坐标转化为世界坐标,然后调用GameManager.Instance.World.IsWater()判断当前世界坐标点是否在水里面 bool flag = GameManager.Instance.World.IsWater(World.worldToBlockPos(pos)); //如果flag成立并且当前载具不是由燃油驱动例如自行车一类的 if (flag && !(__instance.entity is EntityBicycle)) { //进入逻辑,使用Traverse类反射调用方法ApplyDamage销毁载具并附带爆炸效果 EntityVehicle vehicleTarget = __instance.entity; Traverse.Create(vehicleTarget).Method("ApplyDamage", 99999).GetValue(); } } } }
针不戳
这是对自己有多狠啊?
可以改成 丧尸/动物进入水下就死亡的吗,血月的时候 丧尸有时候会在水下挖呀挖,越聚越多 很卡。
我是只发精品mod的作者,所以快关注我吧,支持定制!