Question by
AlvinFassari · Jan 04, 2016 at 02:42 PM ·
script.addcant
cant add script
using UnityEngine;
using System.Collections;
public class GotoMouse : MonoBehaviour {
public float speed = 1.5f;
private Vector3 target;
void Start () {
target = transform.position;
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
i am trying to add this script to my 2d object the object has a 2d box collider and an 2d rigidbody please help me!
Comment
you'll need to add some additional information such as any error messages, etc.
Firstly, please check if name of file and name of class were equal.
Answer by toddisarockstar · Jan 04, 2016 at 07:41 PM
you can't add a script that has an error in your code.pry need to check it again for errors.
As I can see, there aren't compile-time errors in this script
Your answer
Follow this Question
Related Questions
I have problems with Enemy and Player scripts. 0 Answers
Code error :/ 1 Answer
Randomly play multiple attack animation 0 Answers
Set the username with an inputfield ? 3 Answers
How can I add both animator and script rotation on Game object? 0 Answers