2D Platformer tutorial problem (episode 9)

Updated on July 27, 2018 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on July 27, 2018

Hello, i am using unity 2018.1.8f1 .

At brackey’s 2D Platformer tutorial (episode9) when he was making bullet trail, i copied it and when i tested it i could only shoot once.

This is script btw (for moving the trail) :

using UnityEngine;

public class TrailMover : MonoBehaviour {

    public int moveSpeed = 230;

    // Update is called once per frame
    void Update () {
        transform.Translate(Vector3.right * Time.deltaTime * moveSpeed);
        Destroy(gameObject, 1);
    }
}

This is script for shooting:

using UnityEngine;

public class PistolScript : MonoBehaviour {

    public float fireRate = 0f;
    public float damage = 5f;
    public LayerMask whatToHit;

    public Transform BulletTrailPrefab;

    float timeToFire = 0f;
    Transform firePoint;

    // Use this for initialization(but it runs before void Start() { }
    void Awake () {
        firePoint = transform.Find(“FirePoint”);
        if (firePoint == null)
        {
            Debug.LogError(“No FirePoint?”);
        }
    }
    
    // Update is called once per frame
    void Update () {
        if (fireRate == 0)
        {
            if (Input.GetButtonDown(“Fire1”))
            {
                Shoot();
            }

        } else
        {
            if (Input.GetButton (“Fire1”) && Time.time > timeToFire)
            {
                timeToFire = Time.time + 1/fireRate;
                Shoot();
            }
        }
    }
    void Shoot ()
    {
        Debug.Log(“Shoot!”);
        Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
        Vector2 firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y);
        RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition – firePointPosition, 100, whatToHit);
        Effect();
        Debug.DrawLine(firePointPosition, (mousePosition – firePointPosition) * 200, Color.cyan);
        if (hit.collider != null)
        {
            Debug.DrawLine(firePointPosition, hit.point, Color.red);
            Debug.Log(“We hit ” + hit.collider.name + ” and did ” + damage + ” damage “);
        }
    }

    void Effect ()
    {
        Instantiate(BulletTrailPrefab, firePoint.position, firePoint.rotation);
    }
}

What is wrong?

Plz reply soon

  • Liked by
Reply
0 on July 27, 2018

If you see one line of code in multiple lines, that’s just website’s box typing thing, idk

  • Liked by
Reply
Cancel