protected override void Perform(ADLAgent agent) { //Find SubAgentScript by name string spawnAgentName = this.getAgentName(); string spawnDirection = this.getSpawnDirection(); ADLScript subAgentScript = agent.agentScript.subAgentScripts.Find( script => script.agentName.Equals(spawnAgentName)); //Instantiate new Agent Object and Assign SubAgentScript to it GameObject projectile = GameObject.Instantiate(agent.agentPrefab) as GameObject; SpriteRenderer spriteRenderer = projectile.GetComponent <SpriteRenderer>(); spriteRenderer.color = Color.red; ADLAgent subAgent = projectile.GetComponent <ADLAgent>(); subAgent.isInitStateExecuted = false; subAgent.agentScript = subAgentScript; subAgent.agentScript.subAgentScripts = agent.agentScript.subAgentScripts; Vector2 colliderSize = projectile.GetComponent <BoxCollider2D>().size; projectile.transform.localPosition = agent.transform.localPosition; if (spawnDirection.Equals("TowardPlayer")) { try { ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent); if (player.transform.localPosition.x > agent.transform.localPosition.x) { SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Normal); } else { SetProjectilePositionAndDirection(subAgent, ADLBaseAgent.Direction.Inverse); } } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException) { Debug.LogError("Player Not Found: " + e.Message); SetProjectilePositionAndDirection(subAgent, agent.horizonDirection); } } else { SetProjectilePositionAndDirection(subAgent, agent.horizonDirection); } projectile.transform.localScale = new Vector3(this.getWidth() / colliderSize.x, this.getHeight() / colliderSize.y); subAgent.Start(); }
protected override void Perform(ADLAgent agent) { ADLBaseAgent player = ADLBaseAgent.FindAgent("Player", agent.transform.parent); try { if (player.transform.localPosition.x > agent.transform.localPosition.x) { agent.horizonDirection = ADLBaseAgent.Direction.Normal; } else { agent.horizonDirection = ADLBaseAgent.Direction.Inverse; } } catch (Exception e) when(e is NullReferenceException || e is MissingReferenceException) { Debug.LogError("Player Not Found: " + e.Message); } }
// Update is called once per frame void Update() { if (state.Equals(GameState.Running) && isControlledByPlayer) { PlayerInput input = new PlayerInput(ADLBaseAgent.FindAgent("Player", this.transform.parent), Input.GetAxis("Horizontal"), Input.GetButtonDown("Fire1"), Input.GetButtonDown("Jump"), Input.GetButtonUp("Jump")); playerInputSequence.Add(input); // string json = JsonUtility.ToJson(new ListWrapper<Entity>(entities)); // entitiesRecord.Add(json.Substring(8, json.Length - 9)); } if (state.Equals(GameState.End)) { if (this.isFileUploaded) { alertText.text = "Press Enter to Play again"; } else { alertText.text = "Uploading Report ..."; } } }
private ADLBaseAgent GetAgent(int parameterIndex) { string agentName = this.GetStringParameter(parameterIndex); return(ADLBaseAgent.FindAgent(agentName, ADLAgent.currentUpdatingAgent.transform.parent)); }