Hello everyone im stuck with this piece of code.
if enemy got hit then do score + 1 and delete Enemy.
this in in the Movement script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
// A very simplistic car driving on the x-z plane.
public class movement : MonoBehaviour
{
public UpgradeMessageGuns UMG;
public int health = 100;
public static int score;
public int highscore;
public Text ScoreText;
public Text HScoreText;
public float speed = 6.0f;
public float rotationSpeed = 75.0f;
void Update()
{
ScoreText.text = "Score: " + score.ToString();
// Get the horizontal and vertical axis.
// By default they are mapped to the arrow keys.
// The value is in the range -1 to 1
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
// Make it move 10 meters per second instead of 10 meters per frame...
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
// Move translation along the object's z-axis
transform.Translate(0, 0, translation);
// Rotate around our y-axis
transform.Rotate(0, rotation, 0);
if (health < 1)
{
Destroy(gameObject);
}
}
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Bonus")
{
UMG.ActivateGuns();
Destroy(collision.gameObject);
}
if (collision.gameObject.tag == "Enemy" && health>0)
{
health -= health - 10;
Destroy(collision.gameObject);
}
}
public void addscore()
{
score++;
}
}
BulletDelete script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletDelete : MonoBehaviour
{
public Movement movement;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Destroy(gameObject, 1);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
movement.score++;
DestroyObject(collision.gameObject);
}
}
}