protected void Trigger() { if (isTriggered) { return; } GameObject controlledObj = skill.manager.currentObject; BoxCollider2D controlledCollider = controlledObj.GetComponent <BoxCollider2D>() as BoxCollider2D; if (!collider.IsTouching(controlledCollider)) { return; } spriteRenderer.sprite = triggeredSprite; if (target != null) { target.SendMessage("startMoving"); } isTriggered = true; SFXUtils.PlayOnce(SFXUtils.Clips.Switch, 1.0f); if (controlledObj != player) { skill.takeBackControll(); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.layer == 8 && collision.transform.position.y < initialY - 1.5) { SFXUtils.PlayOnce(SFXUtils.Clips.WoodenBox, 1.0f); } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Z) && gameObject.GetComponent <MoveController>().grounded) { if (GetComponent <Player>().controlled) { if (controlTarget != null) { DPtimer += Time.deltaTime; } else { DPtimer = 0; } } else { DPtimer += Time.deltaTime; } if (DPtimer >= skillDP) { if (GetComponent <Player>().controlled) { useControllSkill(); DPtimer = 0; SFXUtils.PlayOnce(SFXUtils.Clips.Control, 1.0f); } else { takeBackControll(); DPtimer = 0; SFXUtils.PlayOnce(SFXUtils.Clips.Discontrol, 1.0f); } } } else if (Input.GetKeyDown(KeyCode.X)) // TODO: Change this { switchTriggerEvent.Invoke(); } else { DPtimer = 0; } //! only for test //manager.showSkillBar(DPtimer / skillDP); }
IEnumerator Break() { yield return(new WaitForSeconds(delay)); SpriteRenderer renderer = sprite.GetComponent <SpriteRenderer>() as SpriteRenderer; renderer.enabled = false; sprite1.SetActive(true); sprite2.SetActive(true); gameObject.SetActive(false); ParticleSystem sys = sprite.GetComponent <ParticleSystem>() as ParticleSystem; if (sys != null) { sys.Play(); } SFXUtils.PlayOnce(SFXUtils.Clips.Brickbreaking, 1.0f); }
public void ControlMove() { if (!canMove) { return; } float horizontal = Input.GetAxis("Horizontal"); moveVelocity = horizontal * moveSpeed; if (horizontal != 0) { transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * (horizontal < 0 ? -1 : 1), transform.localScale.y, transform.localScale.z); if (animator != null) { animator.SetBool("Moving", true); } } else { if (animator != null) { animator.SetBool("Moving", false); } } Vector2 velocity = GetComponent <Rigidbody2D>().velocity; velocity.x = Mathf.SmoothDamp(velocity.x, moveVelocity, ref dampVelocity, dampTime); if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) && grounded) { velocity.y = jumpHeight * 1.4f; if (animator != null) { animator.SetTrigger("Jump"); } SFXUtils.PlayOnce(SFXUtils.Clips.Jump, 1.0f); } GetComponent <Rigidbody2D>().velocity = velocity; }
void FixedUpdate() { Rigidbody2D body = GetComponent <Rigidbody2D>(); if (Mathf.Abs(body.velocity.y) > jumpHeight * 1.4f * 0.55f) { body.gravityScale = 2.0f; } //if (body.velocity.y != 0) Debug.Log(body.velocity.y); if (!canMove) { body.velocity = new Vector2(0, body.velocity.y); } Collider2D collider = Physics2D.Raycast(transform.position, Vector2.down, 0.1f, WhatIsGround).collider; if (collider != null) { if (!grounded) { if (firstTimeGround) { firstTimeGround = false; } else { SFXUtils.PlayOnce(SFXUtils.Clips.Fall, 1.0f); } } grounded = true; groundTag = collider.gameObject.tag; } else { grounded = false; } if (animator != null) { animator.SetBool("Hovering", !grounded); } }
// Update is called once per frame void Update() { if (controlled) { playerMove.canMove = true; playerMove.ControlMove(); } else { playerMove.canMove = false; } var hit = Physics2D.Raycast(face.position, new Vector2(Mathf.Cos(77.71f * Mathf.Deg2Rad), Mathf.Sin(77.71f * Mathf.Deg2Rad)), Mathf.Infinity, LayerMask.GetMask("Floor") | LayerMask.GetMask("Hole") | LayerMask.GetMask("Shelter")); if (hit.collider == null || LayerMask.LayerToName(hit.transform.gameObject.layer) == "Hole") { gameManager.GameOver(); SFXUtils.PlayOnce(SFXUtils.Clips.Burnout, 1.0f); } }