Search Unity

Hi can you review this code

Discussion in 'Scripting' started by Tangoxx, Mar 31, 2015.

?

good/bad

  1. good

    0 vote(s)
    0.0%
  2. bad

    0 vote(s)
    0.0%
  1. Tangoxx

    Tangoxx

    Joined:
    Mar 31, 2015
    Posts:
    2
    using UnityEngine;
    using System.Collections;
    //script only works if you have a tag named Player
    //for best effect use a prefab
    public class MissileScript : MonoBehaviour
    {

    public Transform target;
    public float speed = 3f;
    private bool ifTarget = false;


    public void SetTarget(Transform helTrag)
    {
    target = helTrag;
    ifTarget = true;
    }
    // Use this for initialization
    void Start ()
    {
    SetTarget (target); //temp. call set target when intsintingings

    }

    void Update ()
    {
    if(ifTarget)
    {

    //roates the projectile this make it able for you to dodge the following projectile
    Vector3 toTarget = target.position - transform.position;
    Quaternion rotation = Quaternion.LookRotation(toTarget);

    transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, Time.deltaTime*250f);
    //lucnh the projectile fowards
    GetComponent<Rigidbody>().velocity = transform.forward * speed;


    //transform.rotation = new Quaternion(Mathf.LerpAngle(transform.rotation.x,
    //transform.LookAt(toTarget);

    //Vector3 toTarget = target.position - transform.position;
    //GetComponent<Rigidbody>().velocity = toTarget.normalized * speed;

    //transform.forward = toTarget.normalized;
    }
    }
    }
    thisis my first post, dont be rude!
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Please use code tags!
     
    rakkarage likes this.