hi im trying to write a script for my game i cant figure out the problem just trying to reload current active scene when i collide with enemy. the code is in the last line thanks for any help peeps.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
float xInput;
float yInput;
public float Speed = 10f;
Rigidbody rb;
GameObject Winner;
public float Jump = 50;
void Start()
{
rb = GetComponent();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * Jump);
}
xInput = Input.GetAxis(“Horizontal”);
yInput = Input.GetAxis(“Vertical”);
rb.AddForce(xInput * Speed, 0, yInput * Speed);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == “Shape”)
{
Destroy(collision.gameObject);
}
if (collision.gameObject.tag == “Enemy”)
{
SceneManager.LoadScene(SceneManager.GetActiveScene);
}
}
}[/code]