using UnityEngine;
using UnityEngine.SceneManagement;
public class Bird : MonoBehaviour
{
Vector3 _initialPosition;
private bool _birdWasLaunched;
private float _timeSittingAround;
[SerializeField]private float _launchPower = 500;
private void Awake()
{
_initialPosition = transform.position;
}
private void Update()
{
if (_birdWasLaunched &&
GetComponent().velocity.magnitude <= 0.1);
{
_timeSittingAround += Time.deltaTime;)
}
if (transform.position.y > 10 ||
transform.position.y < -10 ||
transform.position.x > 10 ||
transform.position.x < -11.5 ||
_timeSittingAround > 3)
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
}
private void OnMouseDown()
{
GetComponent().color = Color.red;
}
private void OnMouseUp()
{
GetComponent().color = Color.white;
Vector2 directionToInitialPosition = _initialPosition - transform.position;
GetComponent().AddForce(directionToInitialPosition * _launchPower);
GetComponent().gravityScale = 1;
_birdWasLaunched = true;
}
private void OnMouseDrag()
{
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(newPosition.x, newPosition.y);
}
}
The emoji is from a ; ) I put, It wont let me edit the post.
In your actual code have you put tabs? Maybe Unity couldn’t detect the curly brackets.
I’m just 9, so I’m not really sure about this
1 Like
raarc
October 20, 2020, 2:43pm
4
TheOneTheTruly:
using UnityEngine;
using UnityEngine.SceneManagement;
public class Bird : MonoBehaviour
{
Vector3 _initialPosition;
private bool _birdWasLaunched;
private float _timeSittingAround;
[SerializeField]private float _launchPower = 500;
private void Awake()
{
_initialPosition = transform.position;
}
private void Update()
{
if (_birdWasLaunched &&
GetComponent().velocity.magnitude <= 0.1);
{
_timeSittingAround += Time.deltaTime;)
}
if (transform.position.y > 10 ||
transform.position.y < -10 ||
transform.position.x > 10 ||
transform.position.x < -11.5 ||
_timeSittingAround > 3)
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
}
private void OnMouseDown()
{
GetComponent().color = Color.red;
}
private void OnMouseUp()
{
GetComponent().color = Color.white;
Vector2 directionToInitialPosition = _initialPosition - transform.position;
GetComponent().AddForce(directionToInitialPosition * _launchPower);
GetComponent().gravityScale = 1;
_birdWasLaunched = true;
}
private void OnMouseDrag()
{
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(newPosition.x, newPosition.y);
}
}
remove ; from here
GetComponent<RigidBody2D>().velocity.magnitude <= 0.1);
should be
GetComponent<RigidBody2D>().velocity.magnitude <= 0.1)
you might have more errors after this, by the way the error logs point you to the line where the error is
You have exactly 3 issues, 2 which will lead to compiler errors and one logical error that was already pointed out by raarc.
Specifically:
inside Update you misspellt “Rigidbody2D” as “RigidBody2D”.
Next issue is your “emoji” as there shouldn’t be a “)” after the semicolon.
The last issue is the semicolon after your if statement inside Update. It would essentially disconnect the if statement from the following code block. That’s syntactically not an error (VS usually gives a warning) but it would render your if statement useless and the actual block that follows runs unconditionally.