Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

reload active scene help

Discussion in 'Scripting' started by wicky7772, Jan 16, 2021.

  1. wicky7772

    wicky7772

    Joined:
    Apr 16, 2020
    Posts:
    6
    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<Rigidbody>();
    }


    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]
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520