[SOLVED] Invalid expression term '=='?

Hi there,
I’m currently challenging myself a little bit to implement the winning mechanic without watching how to do it first. I keep getting the Invalid expression term ‘==’ error message. I’ve searched online for how to fix my problem but i’ve had no luck. It seems to me like it should be working as I’m using an ‘if statement’ to check if two strings are identical.
inb4 “code is inefficient”, I’m planning on making it more efficient after I get it working. I have opened up the regions where I believe the problem to reside, please do ask if you want any more screenshots.

There are several issues here. GetActiveScene is a method, so it needs parentheses when called, and it returns a Scene, not a string. The Scene does have a string variable called name though, so you can fetch that. The other problem you have is with parentheses and semicolons, you’re putting some extraneous ones in your code after the if statements.
Try:

string activeScene = SceneManager.GetActiveScene().name;

if (activeScene == "level_2") {
    nextLevel = "level_3";
}
2 Likes

Thanks again for the second time today haha :slight_smile:

Well, I haven’t got many things to do today :wink:

1 Like

Hi, i started making 2d game in unity but i got error error CS1525: Invalid expression term ‘=’.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Kretanje : MonoBehaviour
{
private Rigidbody2D rb;

private Animator myAnimator;

public float movementSpeed;

private bool facingRight;

[SerializeField]
private Transform groundPoints;

[SerializeField]
private float groundRadius;

private LayerMask whatIsGround;

private bool IsGrounded;

private bool jump;

private float jumpForce;

private bool attack;

// Start is called before the first frame update

void Start()
{


facingRight = true;

    rb = GetComponent<Rigidbody2D>();

    myAnimator = GetComponent<Animator>();
}
void Update()
{
HandleInput();
}
// Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");

  isGrounded = IsGrounded();

    HandleMovement(horizontal);

    Flip(horizontal);

    HandleAttacks();

    ResetValues();
}
private void HandleMovement(float horizontal)
{
if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
{
 rb.velocity = new Vector2(horizontal * movementSpeed,rb.velocity.y);
}

if (isGrounded && jump)
{
    isGrounded = false;
    rb.AddForce(new Vector2(0, jumpForce));
}

rb.velocity = new Vector2(horizontal * movementSpeed,rb.velocity.y);

myAnimator.SetFloat("speed",Mathf.Abs(horizontal));
}
private void HandleInput()
{
if (Input.GetKeyDown(KeyCode.Space))
{
    jump = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift)){
    attack = true;
}
}
private void Flip(float horizontal)
{
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x*= -1;
transform.localScale = theScale;
}

}

private void HandleAttacks()
{
if (attack){
    myAnimator.SetTrigger("attack");
    rb.velocity = Vector2.zero;
}

}
private void ResetValues()
{
    attack = false;
}
private bool IsGrounded()
{
    if (rb.velocity.y <= 0)
    {
        foreach (Transform point in groundPoints)
       {                                                                                                 
        Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);

        for (int i = 0; i< colliders.Lenght; i++)
        {
            if (colliders[i].gameObject != gameObject)
            {
                return = true;
            }
        }
        }
    }

}

}

afternoon and welcome to the community :wave:

what line are you getting this error on?

Privacy & Terms