my script does not work
I am making my first game it is just pac-man but I cant do the script plz help here is the script using UnityEngine; using System.Collections;
public class PacmanMove : MonoBehaviour { public float speed = 0.4f; Vector2 dest = Vector2.zero;
void Start() {
dest = transform.position;
}
void FixedUpdate() {
Vector2 p = Vector2.MoveTowards(transform.position, dest, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
}
bool valid(Vector2 dir) {
Vector2 pos = transform.position;
RaycastHit2D hit = Physics2D.Linecast(pos + dir, pos);
return (hit.collider == collider2D);
}
}
void FixedUpdate() { // Move closer to Destination Vector2 p = Vector2.MoveTowards(transform.position, dest, speed); GetComponent().MovePosition(p);
// Check for Input if not moving
if ((Vector2)transform.position == dest) {
if (Input.GetKey(KeyCode.UpArrow) && valid(Vector2.up))
dest = (Vector2)transform.position + Vector2.up;
if (Input.GetKey(KeyCode.RightArrow) && valid(Vector2.right))
dest = (Vector2)transform.position + Vector2.right;
if (Input.GetKey(KeyCode.DownArrow) && valid(-Vector2.up))
dest = (Vector2)transform.position - Vector2.up;
if (Input.GetKey(KeyCode.LeftArrow) && valid(-Vector2.right))
dest = (Vector2)transform.position - Vector2.right;
}
// Animation Parameters
Vector2 dir = dest - (Vector2)transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}
Answer by jgodfrey · Feb 25, 2016 at 01:00 AM
Honestly, you're not going to get far in game development without some scripting knowledge. So, you probably either need to put together a team of people with varying talents (coding, artwork, sound design, modeling, etc), or you're going to have to commit to learning enough to do it all yourself.
This place is great when you're having a specific problem, need some advice, or just a push in the right direction. However, it's not a place where you can just drop in and ask for a "pacman script". There's a lot that goes into the development of a complete game - even a relatively simple game like pacman. You can't expect someone else to provide that via a simple forum request.
I suggest you buckle down, take a look at some tutorials, and begin to learn the process. It's not necessarily easy, but it is rewarding.
Good luck.