Question by
madman_118 · Aug 26, 2015 at 10:45 PM ·
unity 5error messageassetsmonodeveloperror-cs1525
Hi im getting this error in my script Assets/MouseManager.cs(11,27): error CS1525: Unexpected symbol `Vector3'
using UnityEngine; using System.Collections;
public class MouseManager : MonoBehaviour {
void Update() {
if( Input.GetMouseButtonDown (0)
// We clicked, but on what?
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(Input.mouseWorldPos3D.x, Input.mouseWorldPos3D.y);
Vector2 dir = Vector2.zero;
RaycastHit2D hit = Physics2D.Raycast (mousePos2D, dir);
if(hit != null && hit.collider!=null) {
// We clicked on SOMETHING that has a collider
if(hit.collider.rigidbody2D !=null) {
hit.collider.rigidbody2D.gravityScale = 1;
}
}
}
}
Comment
Best Answer
Answer by Dave-Carlile · Aug 27, 2015 at 01:02 PM
Your if
is missing the closing parentheses, and the opening brace...
if( Input.GetMouseButtonDown (0) ) // <-- add a )
{ // <-- add {
... the rest of the stuff ....
} // <-- add this at the end
You should end up with this:
using UnityEngine;
using System.Collections;
public class MouseManager : MonoBehaviour
{
void Update()
{
if(Input.GetMouseButtonDown(0))
{
// We clicked, but on what?
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(Input.mouseWorldPos3D.x, Input.mouseWorldPos3D.y);
Vector2 dir = Vector2.zero;
RaycastHit2D hit = Physics2D.Raycast (mousePos2D, dir);
if(hit != null && hit.collider!=null)
{
// We clicked on SOMETHING that has a collider
if(hit.collider.rigidbody2D !=null)
{
hit.collider.rigidbody2D.gravityScale = 1;
}
}
}
}
}
Pay close attention to how you format and indent things - make sure the formatting is consistent and the braces/brackets line up. It really helps identifying missing things.
Answer by Wolfshadow · Aug 27, 2015 at 12:34 AM
You need brackets over
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(Input.mouseWorldPos3D.x, Input.mouseWorldPos3D.y);
Like this: {
}
im doing this {Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);} {Vector2 mousePos2D = new Vector2(Input.mouseWorldPos3D.x, Input.mouseWorldPos3D.y);}