public bool addNewMissile(GameObject missile, missileType mType) { switch (mType) { case(missileType.Homing): if (homingMissileObject != null) { return false; } homingMissileObject = missile; navPoint homingNav = homingMissileObject.GetComponentInChildren<navPoint> (); homingNav.playerColor = playerColor; homingNav.nameTag = nameTag; homingNav.refresh(); mC = homingMissileObject.GetComponentInChildren<homingMissileScript> (); mC.tLC = this; return true; case(missileType.Controlled): if (controlledMissileOjbect != null) { return false; } controlledMissileOjbect = missile; navPoint contNav = controlledMissileOjbect.GetComponentInChildren<navPoint> (); contNav.playerColor = playerColor; contNav.nameTag = nameTag; contNav.refresh (); contMisScript = missile.GetComponentInChildren<ControlledMissile> (); contMisScript.tLC = this; return true; case(missileType.Collector): Debug.Log("Received fire command"); if(ResourceMissile != null) { return false; } Debug.Log("Setting up AI missile"); ResourceMissile = missile; navPoint rescontNav = ResourceMissile.GetComponentInChildren<navPoint>(); rescontNav.playerColor = playerColor; rescontNav.nameTag = nameTag; rescontNav.refresh(); resourceMissileScript = missile.GetComponentInChildren<resourceRobot>(); resourceMissileScript.tLC = this; Debug.Log("Returning true"); return true; case(missileType.DefenseSystem): if(DefenseSystem != null){ return false; } DefenseSystem = missile; DefenseSystemScript = missile.GetComponentInChildren<defensesystem>(); DefenseSystemScript.tLC = this; return true; default: return false; } }
// Update is called once per frame void Update() { if(missile == null) { missile = transform.parent.gameObject.GetComponentInChildren<homingMissileScript>(); } if(transform.position.y > 50 || transform.position.y < -50) { selfDestruct(); } if(hasTarget) { //transform.parent.up = Vector3.Slerp(transform.forward,target.transform.position - transform.parent.position,Time.time/10000f); Vector3 direction = target.transform.position - transform.parent.position; Vector3 currDirection = transform.forward; if((direction - currDirection + transform.right).magnitude < (direction - currDirection).magnitude) { Left(); } else if((direction - currDirection - transform.right).magnitude < (direction - currDirection).magnitude) { Right(); } if((direction - currDirection + transform.up).magnitude < (direction - currDirection).magnitude) { Down(); } else if((direction - currDirection - transform.up).magnitude < (direction - currDirection).magnitude) { Up(); } } if(camType == ControlType.Inset && rectWidth < .2) { rectWidth += .4f*Time.deltaTime; if(rectWidth >= .2f) { rectWidth = .2f; } viewRect = new Rect(.85f - rectWidth/2f,.15f - rectWidth/2f,rectWidth,rectWidth); camera.rect = viewRect; } else if(camType == ControlType.None && rectWidth > 0) { rectWidth -= .4f*Time.deltaTime; if(rectWidth <= 0f) { rectWidth = 0f; camera.enabled = false; } viewRect = new Rect(.85f - rectWidth/2f,.15f - rectWidth/2f,rectWidth,rectWidth); camera.rect = viewRect; } if(camType == ControlType.Full && !hasTarget) { if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { Up(); } else if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { Down(); } if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { Left(); } else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { Right(); } } if(camType == ControlType.Full) { if(Input.GetKeyDown(KeyCode.LeftShift)) { if(hasTarget) { hasTarget = false; missile.toggleTarget(); target = null; } else { aquireTarget(); } } } if(camType == ControlType.Full && !justActivated) { if(Input.GetKeyDown(KeyCode.E)) { transferControl(); } if(Input.GetKeyDown(KeyCode.LeftShift)) { } } if(camType != ControlType.None) { if(Input.GetKey(KeyCode.Space)) { homingMissileScript msS = transform.parent.gameObject.GetComponent<homingMissileScript>(); msS.kill(); } } justActivated = false; }
// Update is called once per frame void Update() { if (ownedByCurrentPlayer ()) { if (!coloredParent) { navPoint toColor = gameObject.transform.parent.gameObject.GetComponentInChildren<navPoint> (); if (toColor != null) { toColor.playerColor = playerColor; toColor.nameTag = nameTag; toColor.playerTeam = teamNum; toColor.refresh (); coloredParent = true; } } if (mC == null && homingMissileObject != null) { mC = homingMissileObject.GetComponent<homingMissileScript> (); } if (tPT == null) { tPT = thirdPerson.GetComponent<thirdPersonTower> (); if (tPT != null && !isActive) { tPT.shutDownControl (); } } if (fPT == null) { fPT = firstPerson.GetComponent<firstPersonTower> (); } } if (Input.GetKeyDown(KeyCode.K)) { print("ASOUAHDOUAHDOUAHDOAUDH"); manager.scrollFromTab(); } }
// Update is called once per frame void Update() { if(missile == null) { missile = transform.parent.gameObject.GetComponentInChildren<homingMissileScript>(); } if(ownedByCurrentPlayer()) { if(transform.position.y > 200 || transform.position.y < -200 || transform.position.x > 300 || transform.position.x <-300 || transform.position.z > 300 || transform.position.z < -300) { selfDestruct(); } if(hasTarget) { //transform.parent.up = Vector3.Slerp(transform.forward,target.transform.position - transform.parent.position,Time.time/10000f); Vector3 direction = target.transform.position - transform.parent.position; Vector3 currDirection = transform.forward; transform.parent.up = Vector3.Slerp(currDirection,direction,Time.deltaTime*.5f); transform.parent.rotation = Quaternion.Euler(new Vector3(transform.parent.eulerAngles.x,0,transform.parent.eulerAngles.z)); /*if((direction - currDirection + transform.right).magnitude < (direction - currDirection).magnitude) { Left(); } else if((direction - currDirection - transform.right).magnitude < (direction - currDirection).magnitude) { Right(); } if((direction - currDirection + transform.up).magnitude < (direction - currDirection).magnitude) { Down(); } else if((direction - currDirection - transform.up).magnitude < (direction - currDirection).magnitude) { Up(); }*/ } if(camType == ControlType.Inset && rectWidth < .2) { rectWidth += .4f*Time.deltaTime; if(rectWidth >= .2f) { rectWidth = .2f; } viewRect = new Rect(.85f - rectWidth/2f,.15f - rectWidth/2f,rectWidth,rectWidth); camera.rect = viewRect; } else if(camType == ControlType.None && rectWidth > 0) { rectWidth -= .4f*Time.deltaTime; if(rectWidth <= 0f) { rectWidth = 0f; camera.enabled = false; } viewRect = new Rect(.85f - rectWidth/2f,.15f - rectWidth/2f,rectWidth,rectWidth); camera.rect = viewRect; } if(camType == ControlType.Full && !hasTarget) { float y = Input.GetAxis("Mouse Y"); float x = Input.GetAxis("Mouse X"); transform.parent.Rotate(new Vector3(-y, 0, x) * Time.deltaTime * 20,Space.Self); Debug.Log("Euler Angles pre fix: " + transform.parent.eulerAngles); transform.parent.eulerAngles = new Vector3(transform.parent.eulerAngles.x,transform.eulerAngles.y,0); Debug.Log("Euler Angles post fix: " + transform.parent.eulerAngles); //transform.parent.rotation = Quaternion.Euler(new Vector3(transform.parent.eulerAngles.x,0,-transform.parent.eulerAngles.z)); if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { Up(); } else if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { Down(); } if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { Left(); } else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { Right(); } } if(camType == ControlType.Full && !justActivated) { if(Input.GetMouseButtonDown(1)) { if(hasTarget) { hasTarget = false; //missile.toggleTarget(); target = null; } else { aquireTarget(); } } if(Input.GetAxis("Mouse ScrollWheel") != 0) { transferControl(); } if(Input.GetMouseButtonDown(0)) { homingMissileScript msS = transform.parent.gameObject.GetComponent<homingMissileScript>(); msS.kill(); } } if(camType != ControlType.None) { if(Input.GetKey(KeyCode.Space)) { homingMissileScript msS = transform.parent.gameObject.GetComponent<homingMissileScript>(); msS.kill(); } } justActivated = false; } }