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;
}
}
}
}
You need brackets over
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(Input.mouseWorldPos3D.x, Input.mouseWorldPos3D.y);
Like this:
{
}
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.