// Update is called once per frame void Update() { // using unity getComponent system //score = GameObject.Find("Rick").GetComponent<RickController>().score; // using EzMsg / standard form (using lambda) score = EzMsg.Request <IScore, int?>(scoreMgr, _ => _.GetScore()); timeUntilSpawn -= Time.deltaTime; if (timeUntilSpawn <= 0) { Vector3 newPos = new Vector3(1.5f, 1.5f, 0); Instantiate(rock, newPos, Quaternion.identity); if (score <= 5) { timeUntilSpawn = Random.Range(1.8f, 2.2f); } else if (score > 5 && score <= 10) { Debug.Log("oi"); timeUntilSpawn = Random.Range(1.3f, 1.8f); } else if (score > 10 && score <= 15) { timeUntilSpawn = Random.Range(1.0f, 1.4f); } else if (score > 15) { timeUntilSpawn = Random.Range(0.5f, 1.0f); } } }
void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Coin") { EzMsg.Send <IScoreCount>(gameObject, _ => _.ApplyScore(point)) .Wait(0.5f) .Run(); // gSceneManager.Instance.score++; source.PlayOneShot(coinSound, 1.0f); Destroy(collision.gameObject); } var pontos = EzMsg.Request <IScoreCount, float?>(gameObject, GetpointScore); }
/// <summary>Shorthand extension method for EzMsg.Request(gameObject, eventFunc). Eg.: /// int h1 = EzMsg.Request<IArmor, int>(col.gameObject, _=>_.GetHealth()); /// </summary> /// <param name="gO">Target GameObject</param> /// <param name="eventFunc">Method to be executed</param> /// <param name="sendToChildren">Should the request be sent to children of Target?</param> /// <typeparam name="T1">System Handler Interface Type</typeparam> /// <typeparam name="T2">Return type</typeparam> /// <returns></returns> public static T2 Request <T1, T2>(this GameObject gO, EzMsg.EventFunc <T1, T2> eventFunc, bool sendToChildren = true) where T1 : IEventSystemHandler { return(EzMsg.Request(gO, eventFunc, sendToChildren)); }
void Update() { #region Score and Health Text Update // using EzMsg / standard form (using lambda) score = EzMsg.Request <IScore, int?>(scoreMgr, _ => _.GetScore()); scoretext.text = "SCORE: " + score; healthtext.text = "HP: " + health; #endregion invincible = EzMsg.Request <IInvincibility, bool>(rickMgr, _ => _.GetInvincible()); #region Invincibility //if (invincible == true) { // Color tmp = _rb.GetComponent<SpriteRenderer>().color; // tmp.a = 0.5f; // _rb.GetComponent<SpriteRenderer>().color = tmp; // timer += Time.deltaTime; // seconds = (int)timer % 60; // if (seconds == 3) { // tmp.a = 1.0f; // _rb.GetComponent<SpriteRenderer>().color = tmp; // source.PlayOneShot(restore); // invincible = false; // timer = 0; // } //} if (invincible == true) { Debug.Log("OLHA LA"); EzMsg.Send <IInvincibility>(rickMgr, _ => _.isInvincible()). Wait(3f). Send <IInvincibility>(rickMgr, _ => _.isNotInvincible()). Run(); } #endregion #region Calling Jump Method if ((Input.GetButton("Jump") || Input.touches.Length > 0) && _groundCheck == true) { _anim.SetBool("isjumping", true); DoJump(); } #endregion #region Ground Check if (Input.GetKeyDown("space")) { source.PlayOneShot(jump, 0.5f); } if (_rb.transform.position.y >= 0.2) { _groundCheck = false; } if (_rb.transform.position.y <= -0.4) { _groundCheck = true; } #endregion #region Raycast to Score int layerMask = 1 << 11; RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, Mathf.Infinity, layerMask); if (hit.collider != null) { didScore = true; } #endregion }