using System.Collections; using System.Collections.Generic; using UnityEngine; public class Hit : MonoBehaviour { [SerializeField] float swingspeed = 20f; [SerializeField] int pointsForEnemyDeath = 200; Rigidbody2D myRigidbody; PlayerMovement player; float xSpeed; void Start() { myRigidbody = GetComponent(); player = FindObjectOfType(); xSpeed = player.transform.localScale.x * swingspeed; DestroyBulletAfterTime(1f); } void Update() { myRigidbody.velocity = new Vector2 (xSpeed, 0f); } void OnTriggerEnter2D(Collider2D other) { if(other.tag == "enemy") { Destroy(other.gameObject); FindObjectOfType().AddToScore(pointsForEnemyDeath); Destroy(gameObject); } Destroy(gameObject); } void OnCollisionEnter2D(Collision2D other) { Destroy(gameObject); } void DestroyBulletAfterTime(float delay) { Destroy(gameObject, delay); } }