usingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;publicclassDragonMovement:MonoBehaviour{publicList<Renderer>solids;publicfloathorizontalSpeed=0.1f;publicfloatverticalSpeed=0.2f;publicfloathorizontalBound=6f;publicfloatverticalBound=4f;publicHealthBarhealthBar;privateSwarmSystemswarm;privateenumState{normal,swirl,slim,spread};privateStatestate=State.normal;privatevoidmoveUp(){transform.Translate(Vector3.up*verticalSpeed);if(transform.position.y>verticalBound)transform.position=newVector3(transform.position.x,verticalBound,transform.position.z);}privatevoidmoveDown(){transform.Translate(Vector3.down*verticalSpeed);if(transform.position.y<-verticalBound)transform.position=newVector3(transform.position.x,-verticalBound,transform.position.z);}privatevoidmoveLeft(){transform.Translate(Vector3.left*horizontalSpeed);if(transform.position.x<-horizontalBound)transform.position=newVector3(-horizontalBound,transform.position.y,transform.position.z);}privatevoidmoveRight(){transform.Translate(Vector3.right*horizontalSpeed);if(transform.position.x>horizontalBound)transform.position=newVector3(horizontalBound,transform.position.y,transform.position.z);}privatevoidturnVisible(boolvisible){foreach(Renderersolidinsolids){solid.enabled=visible;}}privateIEnumeratortransformSlim(){while(state==State.slim&&swarm.Collapse<0.8f){swarm.Collapse+=0.05f;yieldreturnnewWaitForSeconds(0.01f);}}privateIEnumeratortransformSpread(){while(state==State.spread&&swarm.Noise<3){swarm.Noise+=0.05f;yieldreturnnewWaitForSeconds(0.01f);}}privateIEnumeratortransformAntiSlim(){while(state==State.normal&&swarm.Collapse>0){swarm.Collapse-=0.07f;yieldreturnnewWaitForSeconds(0.01f);}if(state==State.normal){turnVisible(true);swarm.activate(false);}}privateIEnumeratortransformAntiSpread(){while(state==State.normal&&swarm.Noise>0){swarm.Noise-=0.12f;yieldreturnnewWaitForSeconds(0.01f);}if(state==State.normal){turnVisible(true);swarm.activate(false);}}privatevoidturnSwirl(){resetTurn();turnVisible(false);swarm.activate(true);state=State.swirl;}privatevoidturnSlim(){resetTurn();turnVisible(false);swarm.activate(true);state=State.slim;StartCoroutine("transformSlim");}privatevoidturnSpread(){resetTurn();turnVisible(false);swarm.activate(true);state=State.spread;StartCoroutine("transformSpread");}privatevoidturnAntiSwirl(){if(state==State.swirl){state=State.normal;turnVisible(true);swarm.activate(false);}}privatevoidturnAntiSlim(){if(state==State.slim){state=State.normal;StartCoroutine("transformAntiSlim");}}privatevoidturnAntiSpread(){if(state==State.spread){state=State.normal;StartCoroutine("transformAntiSpread");}}privatevoidresetTurn(){swarm.Collapse=0;swarm.Noise=0;}voidStart(){swarm=GetComponent<SwarmSystem>();swarm.activate(false);}voidUpdate(){// keyboard schemeif(Input.GetKey("w"))moveUp();if(Input.GetKey("a"))moveLeft();if(Input.GetKey("s"))moveDown();if(Input.GetKey("d"))moveRight();if(Input.GetKeyDown("i"))turnSwirl();if(Input.GetKeyUp("i"))turnAntiSwirl();if(Input.GetKeyDown("j"))turnSlim();if(Input.GetKeyUp("j"))turnAntiSlim();if(Input.GetKeyDown("k"))turnSpread();if(Input.GetKeyUp("k"))turnAntiSpread();// xbox schemeif(Input.GetAxis("JoystickY")>0.5f)moveUp();if(Input.GetAxis("JoystickX")<-0.5f)moveLeft();if(Input.GetAxis("JoystickY")<-0.5f)moveDown();if(Input.GetAxis("JoystickX")>0.5f)moveRight();if(Input.GetButtonDown("X"))turnSwirl();if(Input.GetButtonUp("X"))turnAntiSwirl();if(Input.GetButtonDown("A"))turnSlim();if(Input.GetButtonUp("A"))turnAntiSlim();if(Input.GetButtonDown("Y"))turnSpread();if(Input.GetButtonUp("Y"))turnAntiSpread();}voidOnDrawGizmosSelected(){Gizmos.color=Color.cyan;Gizmos.DrawWireCube(Vector3.zero,newVector3(2*horizontalBound,2*verticalBound,0));}voidOnTriggerEnter(Colliderother){EnemyColliderenemy=other.gameObject.GetComponent<EnemyCollider>();if(enemy!=null){healthBar.health--;}}}