Home > Software design >  Tryna Make a 3D Platformer in Unity
Tryna Make a 3D Platformer in Unity

Time:10-03

This's really bugging me, because I've been looking all over for a solution. Excuse my terrible code :/

Error:

RespawnController.cs(13,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

Code:

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RespawnController : MonoBehaviour
{
    public float ResPoint = -16.0f;
    

    // Update is called once per frame
    void Update()
    {
        GameObject.Find("PlayerCapsule").transform.position;
        if (transform.position.y == ResPoint)
        {
            transform.position = new Vector3(0.0f, 0.0f, 0.0f);
        }
    }
}

CodePudding user response:

Consider what would happen if I write a statement in C# like:

10;

Your first reaction to this would probably be "Yeah? 10... what?" It's not clear what is intended by this statement.

That's basically what the following line does:

GameObject.Find("PlayerCapsule").transform.position;

This is a value. You need to do some kind of operation on it.

The next line won't compile either because you don't have any variable named transform.

I assume that you meant to store the result of GameObject.Find in a variable and then refer to it in the if statement.

CodePudding user response:

Ok, so I scrapped this respawn system and opted for a KillZone that moves with the player's X and Z coords. But thank everyone who answered for helping me understand Unity more! :)

  • Related