Walking on the roof

I was thinking about how this could be done. Like when player touches the roof, he could “stick” to that and start walking upside down. Could somebody give an example script or open it up somehow for me?

One solution to begin with is to use Rigidbody. Disable the gravity of your player, and set a y velocity to -yvalue. This way he is constantly pushed down to the ground.

Add a raycast pointing upward at a distance if let’s say 1m. Now if you jump from high enough, your raycast will hit the roof which I think you meant ceiling.

If the roof is tagged ceiling you can check what is hitting the raycast and perform an action and reverse with the ground:

void Update() {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.up, out hit,2f))
            if(hit.collider.tag == "Ceiling" || hit.collider.tag == "Ground")
                  rigidbody.velocity.y *= -1;       
    }

Unity Script:

function Update() {
        var hit :RaycastHit;
        if (Physics.Raycast(transform.position, transform.up, hit,2f))
            if(hit.collider.tag == "Ceiling" || hit.collider.tag == "Ground")
                  rigidbody.velocity.y *= -1;       
    }

Note I gave 2 for length as it starts from the center of your guy which should be 2units by default.