Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Respawn Script (Maxfall)

Discussion in 'Scripting' started by andersdk98, Oct 14, 2015.

  1. andersdk98

    andersdk98

    Joined:
    Feb 3, 2015
    Posts:
    11
    Hey!
    I am currently working on a game, where you are controlling a ball on some grounds n stuff.
    When you fall down, you have to respawn. And I tried following script but it doesn't work:

    #pragma strict

    var maxFall = -10;

    function Update ()
    {
    if (GetComponent.<Rigidbody>().position.y <= maxFall)
    {
    Debug.Log("Test");
    }

    }

    Any ideas?

    Thanks in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
    This is a fairly unhelpful statement. What does it do? Does it not trigger? Did you actually attach it to the gameobject that is falling? Did you put a Start() function in there that tells you that it was even instantiated? Did you try setting a breakpoint at the start of Update()? Is your function even running anywhere? These are things you should be able to instantly ascertain in any and every case of scripting and there are plenty of tutorials to guide you there.
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I don't know Java but I think you should have transform.position.y instead of just position.y
     
  4. andersdk98

    andersdk98

    Joined:
    Feb 3, 2015
    Posts:
    11
    This script worked 4 me :)

    #pragma strict

    var maxFallDistance = -10;

    function Update ()
    {
    if (transform.position.y <= maxFallDistance)

    Application.LoadLevel ("Level01");
    }