Question by
madman_118 · Aug 27, 2015 at 09:23 AM ·
unity 5errormonodeveloperror-cs1525
Help i get this error Assets/MouseManager.cs(11,20): error CS1525: Unexpected symbol `{'
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 Positive7 · Aug 27, 2015 at 09:45 AM
I'm not sure where was your original problem as this script had soo many error. You should declare Vector2 mousePos2D outside the if() otherwise you can't use its value in the Raycast. You were missing a couple of " ; " "hit !=null" always returns true use "hit" instead
using UnityEngine;
using System.Collections;
public class MouseManager : MonoBehaviour {
Vector2 mousePos2D;
void Update() {
if( Input.GetMouseButtonDown (0)){
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos2D = new Vector2(mouseWorldPos3D.x, mouseWorldPos3D.y);
}
Vector2 dir = Vector2.zero;
RaycastHit2D hit = Physics2D.Raycast (mousePos2D, dir);
if(hit && hit.collider && hit.collider.GetComponent<Rigidbody2D>() != null) {
hit.collider.GetComponent<Rigidbody2D>().gravityScale = 1;
}
}
}
i was spending hours fixing one problem then another come up. You are a legend thanks so much :)