private IEnumerator UpdatePath() { if (target == null) { if (!searchingForItem) { searchingForItem = true; StartCoroutine(SearchForObject()); } } else { ExtraCellularProperties objProps = (ExtraCellularProperties)target.GetComponent("ExtraCellularProperties"); if (!objProps.isActive) { searchingForItem = true; StartCoroutine(SearchForObject()); } else { //Component co = this.GetComponent("Extracellular Signal Body"); //co.GetComponent<Renderer>().material.color = Color.red; seeker.StartPath(transform.position, target.position, OnPathComplete); StartCoroutine(UpdatePath()); yield return(new WaitForSeconds(1 / updateRate)); } objProps = null; } }
// Update is called once per frame private void Update() { if (Input.GetKey(KeyCode.F)) { o = GameObject.Find("_ExtraCellularProteinSignaller"); Debug.Log("Found: " + o.name); } if (Input.GetKey(KeyCode.M)) { ExtraCellularProperties myScript = o.GetComponent <ExtraCellularProperties>(); Debug.Log("Changing movememnt to: " + !myScript.allowMovement); myScript.allowMovement = !myScript.allowMovement; } }
private IEnumerator SearchForObject() { GameObject[] gos = GameObject.FindGameObjectsWithTag("ExternalReceptor"); //Component co = GetComponent("Extracellular Signal Body"); //co.GetComponent<Renderer>().material.color = Color.blue; bool FoundObject = false; foreach (GameObject go in gos) { ExtraCellularProperties objProps = (ExtraCellularProperties)go.GetComponent("ExtraCellularProperties"); if (!objProps.isActive) { objProps = null; continue; } else { FoundObject = true; objProps = null; searchingForItem = false; target = go.transform; StartCoroutine(UpdatePath()); break; } } ; gos = null; if (!FoundObject) { Roam(); yield return(new WaitForSeconds(seekTime)); StartCoroutine(SearchForObject()); } }
// Update is called once per frame private void Update() { ExtraCellularProperties myScript = (ExtraCellularProperties)GetComponent("ExtraCellularProperties"); Debug.Log(myScript.allowMovement); if (Input.GetKey(KeyCode.LeftArrow) && myScript.allowMovement) { transform.position += Vector3.left * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.RightArrow) && myScript.allowMovement) { transform.position += Vector3.right * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.UpArrow) && myScript.allowMovement) { transform.position += Vector3.up * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.DownArrow) && myScript.allowMovement) { transform.position += Vector3.down * speed * Time.deltaTime; } }
/* Function: Start() * Purpose: this function is called when initially instantiated. * does some initialization */ private void Start() { ExtraCellularProperties objProps = (ExtraCellularProperties)this.GetComponent("ExtraCellularProperties"); changeState(objProps.isActive); }