This question was
closed Aug 27, 2015 at 04:30 PM by
Dave-Carlile for the following reason:
Duplicate Question: http://answers.unity3d.com/questions/1036750/help-im-getting-this-error-assetsmousemanagercs383-1.html
Question by
madman_118 · Aug 27, 2015 at 03:05 PM ·
unity 5monodeveloperror-cs1525
Help im getting this error Assets/MouseManager.cs(38,32): error CS1525: Unexpected symbol `grabbedObject'
using UnityEngine; using System.Collections;
public class MouseManager : MonoBehaviour {
Rigidbody2D grabbedObject = null;
Vector2 mousePos2D;
float dragSpeed = 4f;
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;
}
if( Input.GetMouseButtonDown (0)){
grabbedObject = null;
}
}
void FixedUpdate() {
if(grabbedObject != null) {
Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos2D = new Vector2(mouseWorldPos3D.x, mouseWorldPos3D.y);
Vector2 dir = mousePos2D - grabbedObject.position;
dir *= dragSpeed
grabbedObject.velocity = dir;
}
}
}
Comment