Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    8

    arcade space shooter tutorial problem?

    i have followed the tutorial exacly up to and compleeting 14.projectile collisions, yet my collision doesnt work can any one see any problems? here the code as its shown in the .cs files

    Enemy.cs

    using UnityEngine;

    using System.Collections;

    public class Enemy : MonoBehaviour

    {
    #region fields

    public float MinSpeed;
    public float MaxSpeed;
    private float CurrentSpeed;
    private float x, y, z;

    #endregion

    #region propertys

    #endregion

    #region functions

    // Use this for initialization

    void Start ()
    {
    setPosistionAndSpeed();
    }

    // Update is called once per frame

    void Update ()
    {
    float amtToMove = CurrentSpeed * Time.deltaTime;
    transform.Translate(Vector3.down * amtToMove);

    if (transform.position.y <= -5)
    {
    setPosistionAndSpeed();
    }
    }

    public void setPosistionAndSpeed()
    {
    CurrentSpeed = Random.RandomRange(MinSpeed, MaxSpeed);
    x = Random.RandomRange(-6, 6);
    y = 7.0f;
    z = 0.0f;

    transform.position = new Vector3(x, y, z);
    }

    #endregion

    }



    Prejectile.cs

    using UnityEngine;
    using System.Collections;

    public class Prejectile : MonoBehaviour {

    public float PrejectileSpeed;

    private Transform myTransform;

    // Use this for initialization
    void Start ()
    {
    myTransform = transform;
    }

    // Update is called once per frame
    void Update ()
    {
    float amtToMove = PrejectileSpeed * Time.deltaTime;
    myTransform.Translate(Vector3.up *amtToMove);

    if (myTransform.position.y > 6.4f)
    Destroy(gameObject);
    }

    void onTriggerEnter (Collider otherObject)
    {
    if (otherObject.tag == "Enemy")
    {
    Enemy enemy = (Enemy)otherObject.gameObject.GetComponent("Enemy" );
    enemy.setPosistionAndSpeed();

    Destroy (gameObject);
    }
    }
    }


    player.cs

    using UnityEngine;
    using System.Collections;

    public class Player : MonoBehaviour {


    public float PlayerSpeed;
    public GameObject PrejectilePrefab;

    // Update is called once per frame
    void Update ()
    {
    float amtToMove = Input.GetAxisRaw ("Horizontal")* PlayerSpeed *Time.deltaTime; // a value that allows to move a distance over 1 sec
    //.GetAxis gives a smooth movement Raw gives a snapping feel like old arcade games
    transform.Translate(Vector3.right * amtToMove);

    //Wrapping player going off screen and comming back on

    if (transform.position.x<= -7.5f)
    transform.position = new Vector3 (7.4f, transform.position.y, transform.position.x); // if player goes of the left bounds apper on the right -7.5 is the bounds

    else if (transform.position.x>= 7.5f)
    transform.position = new Vector3 (-7.4f, transform.position.y, transform.position.x);

    if (Input.GetKeyDown("space"))
    {
    //fire prejectile
    Vector3 position = new Vector3 (transform.position.x, transform.position.y + (transform.localScale.y / 2));
    Instantiate(PrejectilePrefab, position, Quaternion.identity); //make a prejectile
    }
    }
    }

  2. #2
    Join Date
    Jul 2010
    Posts
    21
    In your "Prejectile.cs" file, "onTriggerEnter" should be "OnTriggerEnter"
    A witty saying proves nothing!

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    thank you so much! iv been looking at this for the better part of 2 hours :-/ it works now thank you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •