public override void OnDead() { if (_canDrop) { // TODO: tehokkaampi drop for (int i = 0; i < 10; i++) { DropScript.Drop(ResourceManager.Instance.GetCorpseDrops(), transform); } } }
void Destroy() { if (GetComponent <DropScript>() != null) { DropScript dsp = GetComponent <DropScript>(); if (GetComponent <Collider2D>() != null) { dsp.drop(GetComponent <Collider2D>().bounds.size.y / 2); } else { dsp.drop(0.05f); } } }
/// <summary> /// Start is called on the frame when a script is enabled just before /// any of the Update methods is called the first time. /// </summary> void Start() { animator = GetComponent <Animator>(); m_drop = GetComponent <DropScript>(); }
// Update is called once per frame void Update() { // Detects if the character is moving right. If it is, flips it // horizontally. bool flip = Input.GetKeyDown(KeyCode.RightArrow); if (flip) { dir_right = true; foreach (SpriteRenderer childsr in sr) { childsr.flipX = true; } ani.SetBool("left", false); ani.SetBool("right", true); } // Detects if the character is moving left. If it is, unflips it // horizontally. bool unflip = Input.GetKeyDown(KeyCode.LeftArrow); if (unflip) { dir_right = false; foreach (SpriteRenderer childsr in sr) { childsr.flipX = false; } ani.SetBool("left", true); ani.SetBool("right", false); } // moving horizontally float inputX = Input.GetAxis("Horizontal"); if (!inputX.Equals(0)) { rb.velocity = new Vector2(speed.x * inputX, rb.velocity.y); } //else { // ani.SetBool("left", false); // ani.SetBool("right", false); //} // jumping if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded()) { rb.AddForce(Vector2.up * jumpForce * (float)1.88, ForceMode2D.Impulse); } // dropping a stack of books (usually used for holding buttons) bool drop = Input.GetKeyDown("space"); if (drop) { DropScript drop2 = GetComponent <DropScript>(); if (drop2 != null) { drop2.Drop(); } } // shooting a book at an enemy (attacking) bool shoot = Input.GetKeyDown(KeyCode.RightShift); if (shoot) { WeaponScript weapon = GetComponent <WeaponScript>(); if (weapon != null) { weapon.Attack(false); } } }