#Unity vs

1 messages · Page 1 of 1 (latest)

somber temple
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class gamemanager1 : MonoBehaviour
{

    [SerializeField] Transform myObject;
    [SerializeField]
    [Range(0, 200)]
    int certainValue = 23;
    int negcertainValue = -23;
   void Awake()
    {
        DontDestroyOnLoad(this);
    }
    [SerializeField] int rightSide = 0;
    [SerializeField] int leftSide = 0;
    void Update()
    {
        if (myObject == null)
            return;
        if (myObject.position.x >= certainValue)
        {
            rightSide = rightSide + 1;
        }
        else if (myObject.position.x <= negcertainValue)
        {
            leftSide = leftSide + 1;
        }
        else
        {
            return;
        }

        if (leftSide >= 11 || rightSide >= 3)
        {
            Debug.Log("Check2");
            print("Check");
            SceneManager.LoadScene("Untitled");
        }
        else
        {
            ResetScene();
        }
    }
    public void ResetScene()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
    public void Init(Transform myObject)
    {
        this.myObject = myObject;
    }

    void OnEnable()
    {
        SceneManager.sceneLoaded += OnSceneLoad;
    }
    void OnSceneLoad(Scene scene,LoadSceneMode mode)
    {
        Debug.Log(scene.Untitled);
    }

    void OnDisable()
    {
        SceneManager.sceneLoaded -= OnSceneLoad;
    }
}
``` I have a scene called Untitled, but it is not recognized here, what is the problem?
somber temple
#

'Scene' does not contain a definition for 'Untitled' and no accessible extension method 'Untitled' accepting a first argument type of 'Scene' could be found (are you missing a using directive or an assembly reference?)

grim venture
#

It's because there's no property of Scene called Untitled.

#

@somber temple.

somber temple
#

What's the solution

grim venture
#

Is your scene named "Untitled," and is it added to your build settings?

somber temple
#

Yes

grim venture
#

Hm, proof?

#

This is what my test project without any scenes in it looks like.

somber temple
#

Okay how do i fix this

grim venture
#

You said your scene was already in the build?

somber temple
#

Yeah

grim venture
#

That you can see it when you open Build Settings?

somber temple
#

Yeah

grim venture
#

If what you said is true, it would work, so I just want you to show me screenshots and such. And also the error message.

somber temple
#

'Scene' does not contain a definition for 'Untitled' and no accessible extension method 'Untitled' accepting a first argument type of 'Scene' could be found (are you missing a using directive or an assembly reference?)

grim venture
#

Dude.

somber temple
grim venture
#

There's no such property called Untitled on Scene.

somber temple
#

How do i fix it

grim venture
#

Well, what are you trying to do?

somber temple
#

I want the scene to load

grim venture
#

Okay, then delete the broken line of code.

grim venture
somber temple
#

Alright

#

But that doesn't change the fact that it does not recognize the scene

grim venture
#

Okay, then show me the next error.

somber temple
#

No error now

grim venture
#

If your code compiles, you're calling SceneManager.LoadScene("Untitled");, and the scene is in the build, it should load.

somber temple
#

I agree with you

grim venture
#

Well, I assume it works now.

somber temple
#

No scene doens't load

grim venture
#

Okay.

#

This is the part where you explain your situation in more detail.

#

Any errors?

somber temple
#

No errors

grim venture
#

Does it log "Check2" and "Check"?

somber temple
#

Yep

#

Not sure what else i can tell you

somber temple
grim venture
#

Works for me.

#

😅

somber temple
#

How

grim venture
#

I set up a scene named "Titled."

#

I created another scene named "Untitled."

#

I added "Untitled" to the build.

#

I assigned myObject to "GameObject" in the scene.

#

When I move "GameObject" way to the left, "Untitled" is loaded.

somber temple
#

I did all that

grim venture
#

Then why do you think it's not working?

somber temple
#

I am here looking for help in finding why it's not working

grim venture
#

No, I mean, what are you observing that makes you think that the scene is not being loaded?

somber temple
#

I don't know it should work

grim venture
#

Can you show a video of it not working?

#

You're giving no information.

somber temple
#

Okay well you are doing something there

#

That's not how it goes

grim venture
#

I'm using your code. I needed to trigger the event that causes the scene to load.

#

That's why I'm moving the object to the left.

somber temple
#

Make a game object

grim venture
#

I did.

somber temple
#
using System.Collections.Generic;
using UnityEngine;

public class BallMovement : MonoBehaviour
{


    private Vector3 RandomVector(float min, float max)
    {
        var x = Random.Range(min, max);
        var y = Random.Range(min, max);
        var z = Random.Range(min, max);
        return new Vector3(x, y, z);
    }
    // Start is called before the first frame update
    void Start()
    {
        //var rb = GetComponent<Rigidbody>();
        //rb.velocity = RandomVector(5f, 5f);
        manager = FindObjectOfType<gamemanager1>();
        manager.Init(transform);
        rb.velocity = RandomVector(5f, 5f);

    }

    [SerializeField] Rigidbody rb;
    [SerializeField] float constantSpeed = 10;
    [SerializeField] gamemanager1 manager;
    Vector3 lastVelocity;
    // Update is called once per frame
    void Update()
    {
        lastVelocity = rb.velocity;
        rb.velocity = constantSpeed * (rb.velocity.normalized);
    }
    private void OnCollisionEnter(Collision coll)
    {

        if (coll.collider.GetComponent<EdgeCollider2D>() != null)
        {
            //print("Colliding with edge");
            manager.ResetScene();
        }
        var speed = lastVelocity.magnitude;
        var direction = Vector3.Reflect(lastVelocity.normalized, coll.contacts[0].normal);

        rb.velocity = direction * Mathf.Max(speed, 0f);


    }

    //void OnCollisionEnter(Collision collision)
    //{
    //    if (collision.collider.GetComponent<EdgeCollider2D>() != null)
    //    {
    //        print("Colliding with edge"); 
    //    }
    //}
}
#

Another game object

somber temple
grim venture
#

Yup, got it.

somber temple
grim venture
somber temple
#

You have a ball not a cube

#

Needs to be cube

#

First script on create empty object

#

Second on a cube

#

put cube on idk 0 0 0

grim venture
#

I just don't know what you're even trying to do.

somber temple
#

I want the scene to load after it's reset 3 times

#

It resets after going to 23 on x axis

grim venture
#

Aha, I guess you want to make a game where the ball can reach one of two goals. The game resets once it hits a goal, and once three goals have been scored, "Untitled" is loaded.

somber temple
#

You guess right wagner

grim venture
#

Your initial question was answered, so if you have a more specific question than "how do I make my game," you can ask it.

grim venture
#

It will load when the "ball" reaches either side of your playing field.

#

Well, maybe not, your code is a bit messy.

#

Anyway, if "Check" and "Check2" are logged, then the scene has been loaded.

somber temple
#

object goes back to where it was and after it does that 3 times

#

checks comes and it should load untitled scene

grim venture
#

You're not really asking how to load the scene, because that code already works.

#

It's the rest of your code that isn't behaving the way you want.

somber temple
#

It's seems to me it's the other way around

#

the rest of the code works except for the load line

grim venture
#

I've already shown you that it works.

grim venture
#

I'm just triggering the line that loads the scene.

#

So the load line works.

quick karma
#

Theres a neat little thing called google you know

#

[]google

livid briarBOT
#

Sounds like something https://google.com/ would know!

grim venture
#

[]ddg