Tools to connect objects
usingUnityengine;usingSystem.Collections; Public classTool:monobehaviour {floatHor; Vector3 Movedir; Public floatMovespeed =3f; intScore =0; voidUpdate () {Hor= Input.getaxis ("Horizontal"); //get move Direction vectorMovedir = Hor *Vector3.right; //MovingTransform.position + = Movedir * Time.deltatime *Movespeed; } voidOntriggerenter (Collider other) {if(Other.tag = ="Gold") {Destroy (other.gameobject); Debug.Log (++score); } }}
Create three presets for a drop body
usingUnityengine;usingSystem.Collections; Public classGoldcreater:monobehaviour {//Coin Preset Body PublicGameobject Goldprefab; //time interval to generate coins Public floatInterval =1f; //Timer Private floattimer; //index number Private intindex; voidUpdate () {// Timer TimerTimer + =Time.deltatime; //Timing Complete if(Timer >=interval) { ///TODO: Generate coinsGoldinit (); //timer reset to zeroTimer =0; } } /// <summary> ///Generate coins/// </summary> voidGoldinit () {//Sub-object index number (random)index = Random.range (0,3); //Build LocationVector3 Initpos =transform. Getchild (index). Position; //Generate coinsInstantiate (Goldprefab, Initpos, quaternion.identity); }}
Demon_ Gold (three drop item presets, one-off object tool)