As the title says,i have a problem with my scripts.Probably I can troubleshoot it easly but the problem is,I cant find the problem.Maybe you guys can help me?I guess I want a lot of thing but if I describe good,you guys can help.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class DamagedByCollision : MonoBehaviour
{
public int health = 1;
public float invulnPeriod = 0;
float invulnTimer = 0;
int correctLayer;
public Transform player;
public Transform end;
public Text scoreText;
public Transform enemy;
SpriteRenderer spriteRend;
void Start()
{
correctLayer = gameObject.layer;
spriteRend = GetComponent<SpriteRenderer>();
if (spriteRend == null)
{
spriteRend = transform.GetComponentInChildren<SpriteRenderer>();
if (spriteRend == null)
{
Debug.LogError("Object '" + gameObject.name + "' has no sprite renderer.");
}
}
}
void OnTriggerEnter2D(Collider2D hit)
{
if(end.gameObject.tag == "End")
{
health++;
if (invulnPeriod > 0)
{
invulnTimer = invulnPeriod;
gameObject.layer = 11;
}
}
if (player.gameObject.name == "Air Ship")
{
health--;
if (invulnPeriod > 0)
{
invulnTimer = invulnPeriod;
gameObject.layer = 11;
}
}
if(hit.gameObject.name == "Air Ship")
{
Scene CS = SceneManager.GetActiveScene();
SceneManager.LoadScene(CS.name);
}
}
void Update()
{
if (invulnTimer > 0)
{
invulnTimer -= Time.deltaTime;
if (invulnTimer <= 0)
{
gameObject.layer = correctLayer;
if (spriteRend != null)
{
spriteRend.enabled = true;
}
}
else
{
if (spriteRend != null)
{
spriteRend.enabled = !spriteRend.enabled;
}
}
}
if (health <= 0)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
This is the script that probably making problems.I have a shooting mechanic in my game.It was working fine until today.Bullets are passing through the enemies.If you need more details I am here.