Search Unity

moving in the direction of Camera on mouse click not working

Discussion in 'Scripting' started by BOS1, Jan 26, 2015.

  1. BOS1

    BOS1

    Joined:
    Jan 20, 2015
    Posts:
    1
    hello this is my first post. I'm relatively new to unity and scripting and i've been trying to solve this problem
    all day whenever I mouse click, my character doesn't move i'm using vector3.movetorwards I've tried using rigidbody.addforce, rigidbody.addrelativeforce, transform.translate, rigidbody.moveposition,. some help would be greatly appretiated here's my code: (the goal of this is to make the player move at a high speed on x, y, z based of the rotation of the camera)

    using UnityEngine;
    using System.Collections;
    public class DashMechanic : MonoBehaviour
    {
    public float Dash_Speed;
    public Transform Dash_Source;
    public GameObject Dash_Initiation;
    private bool DashIsNull;
    private Vector3 Dash_Direction;
    private GameObject Dash_Instance;
    void Start ()
    {
    }
    void Update ()
    {
    //sets the variable Dash_Direction to the position of Dash_Source.
    Dash_Direction = new Vector3 (Dash_Source.position.x, Dash_Source.position.y, Dash_Source.position.z);
    if (Input.GetMouseButtonUp (0))
    {
    Dash ();
    }
    if (Input.GetMouseButtonUp (1))
    {
    Dash ();
    }
    }
    void Dash ()
    {
    if (DashIsNull == true)
    {
    // creates an instance of Dash_Initiation
    Dash_Instance = Instantiate (Dash_Initiation, Dash_Source.position, Dash_Source.rotation) as GameObject;
    }
    // used to make sure theres only one instance of Dash_Initiation.
    if (Dash_Instance == null)
    DashIsNull = true;

    else if(Dash_Instance == false)
    {
    GameObject.Destroy (Dash_Instance);
    }
    //moves the player.
    Vector3.MoveTowards (transform.position, Dash_Direction, Dash_Speed * Time.deltaTime);
    }
    }