uni1->C#->装箱拆箱

来源:互联网 发布:java老师王克晶年薪 编辑:程序博客网 时间:2024/05/21 20:26

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style="font-size:32px;">C#->装箱拆箱</span></span>

父类
using UnityEngine;using System.Collections;public class Vehicle {private float Speed;private float MaxSpeed;private float Weight;public void Run(){Debug.Log("Vehicle-Run");}public float speed{set{Speed=value;}get{return Speed;}}public float maxspeed{set{MaxSpeed=value;}get{return MaxSpeed;}}public float weight{set{Weight=value;}get{return Weight;}}public void Stop(){Debug.Log("Vehicle-Stop");}}
子类
using UnityEngine;using System.Collections;public class car :Vehicle {public void Run(){Debug.Log("car-Run"+"speed->"+speed+"\t"+"Weight->"+weight+"\t"+"MaxSpeed"+maxspeed);}public void Stop(){Debug.Log("car-Stop"+"speed->"+speed+"\t"+"Weight->"+weight+"\t"+"MaxSpeed"+maxspeed);}}
引用->装箱拆箱
<pre name="code" class="csharp">using UnityEngine;using System.Collections;public class chen : MonoBehaviour {public bicycle s1=new bicycle();public Vehicle s2=new car();//zhuangxiangvoid Start () {s1.speed = 30;s1.maxspeed = 90;s1.weight = 1000;s2.speed = 50;s2.maxspeed = 120;s2.weight = 1500;s1.Run ();s1.Stop ();s2.Run ();s2.Stop ();car c2 = carRun (s2) as car;//chaixiang}Vehicle carRun(Vehicle c){c.Run ();c.maxspeed = 0;return c;}void Update () {}}





0 0
原创粉丝点击