public void setControlledEnemy(PossessableEnemy e) { if (controlledEnemy != null) { controlledEnemy.leavePlayerControl(); } e.gameObject.tag = "Player"; this.controlledEnemy = e; e.speed = e.speed * playerControlledSpeedMultiplier; Debug.Log(playerControlledSpeedMultiplier); e.enterPlayerControl(); this.transform.SetParent(controlledEnemy.transform); controlledEnemy.GetComponent <SpriteRenderer>().color = new Color(0.7f, 0.7f, 0.95f); playerHealth = e.health; }
// Use this for initialization void Start() { Debug.Log("Warning: If you see this debug message, make sure to maximize on play. OnBecomeInvisible(for bullets) will not work properly without it."); time = 0; levelDuration = 10; //testCode StartCoroutine("spawnEveryTen"); GameObject InitialPlayerGO = Instantiate(enemyPrefabRoot.Find(ENEMYTYPE.simplerobot.ToString()).gameObject); InitialPlayerGO.SetActive(true); PossessableEnemy pEnemy = InitialPlayerGO.GetComponent <PossessableEnemy>(); pEnemy.placeAtCoordinates(Vector2.zero); player.transform.SetParent(InitialPlayerGO.transform); Player playerScript = player.gameObject.GetComponent <Player>(); playerScript.setControlledEnemy(pEnemy); playerScript.playerHealth = 100; //FIXME: Hardcoded value }
// Update is called once per frame void Update() { if (controlledEnemy != null) { Vector3 move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); controlledEnemy.move(move); if (Input.GetKey(KeyCode.Z)) { controlledEnemy.basicAttack(); } if (Input.GetKeyDown(KeyCode.X)) { if (!isTransmitting && playerTransmissionJuice > 0) { GameObject.Find("Game").GetComponent <SoundManager>().playTransmit(); isTransmitting = true; GameObject enemyObj = findClosest(); PossessableEnemy e = enemyObj.GetComponent <PossessableEnemy>(); if (e != null) { leaveControlledEnemy(); setControlledEnemy(e); e.transmitTo(); this.playerTransmissionJuice = Mathf.Max(0, playerTransmissionJuice - LOSSONTRANSMIT); } else { //nothing to transmit to Debug.Log("Not Implemented Exception"); } StartCoroutine("reloadTransmission"); } } Vector3 pos = Camera.main.WorldToViewportPoint(controlledEnemy.transform.position); pos.x = Mathf.Clamp01(pos.x); pos.y = Mathf.Clamp01(pos.y); controlledEnemy.transform.position = Camera.main.ViewportToWorldPoint(pos); } }