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?
#Unity vs
1 messages · Page 1 of 1 (latest)
'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?)
I can't load that scene either
What's the solution
Is your scene named "Untitled," and is it added to your build settings?
Yes
Okay how do i fix this
You said your scene was already in the build?
Yeah
That you can see it when you open Build Settings?
Yeah
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.
'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?)
Dude.
!
There's no such property called Untitled on Scene.
How do i fix it
Well, what are you trying to do?
I want the scene to load
Okay, then delete the broken line of code.
This one.
Okay, then show me the next error.
No error now
If your code compiles, you're calling SceneManager.LoadScene("Untitled");, and the scene is in the build, it should load.
I agree with you
So what now
Well, I assume it works now.
No scene doens't load
Okay.
This is the part where you explain your situation in more detail.
Any errors?
No errors
Does it log "Check2" and "Check"?
So what's next
How
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.
I did all that
Then why do you think it's not working?
I don't know
I am here looking for help in finding why it's not working
No, I mean, what are you observing that makes you think that the scene is not being loaded?
I don't know it should work
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.
Make a game object
I did.
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
@grim venture add a game object with this script
Yup, got it.
Create an empty object and put this on it
So what's the problem?
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
I want the scene to load after it's reset 3 times
It resets after going to 23 on x axis
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.
You guess right wagner
Your initial question was answered, so if you have a more specific question than "how do I make my game," you can ask it.
How do i load the scene
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.
After it goes to x 23 it resets
object goes back to where it was and after it does that 3 times
checks comes and it should load untitled scene
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.
It's seems to me it's the other way around
the rest of the code works except for the load line
I've already shown you that it works.
You just told me that I'm doing something, so it doesn't count. ???
I'm just triggering the line that loads the scene.
So the load line works.
Sounds like something https://google.com/ would know!
Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
[]ddg