Search Unity

want to generate a rebound, found problem

Discussion in 'Scripting' started by abysswolf, Oct 29, 2014.

  1. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnemyLaser01 : MonoBehaviour {
    5.     public Transform tlaser01;
    6.     public float laserLife = 6f;
    7.     public float laserSpeed = 60f;
    8.     public float extradamage = 1;
    9.     public float fwbw = 0f;
    10.     // Use this for initialization
    11.     void Start () {
    12.         tlaser01 = transform;
    13.         fwbw = Random.Range (149f, 225f);
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.  
    19.         laserLife -= Time.deltaTime;
    20.         if (laserLife <= 0) {
    21.             Destroy(this.gameObject);
    22.         };
    23.  
    24.         tlaser01.Translate (Vector3.forward * laserSpeed * Time.deltaTime);
    25.  
    26.  
    27.     }
    28.     void OnTriggerEnter (Collider lasercollider) {
    29.  
    30.         if (lasercollider.CompareTag ("PlayerShip")) {
    31.             PlayerScript.GET.curHealth = PlayerScript.GET.curHealth - extradamage;
    32.             Destroy(this.gameObject);
    33.         };
    34.         if (lasercollider.CompareTag ("PlayerShield")) {
    35.             Debug.Log ("entered");
    36.             this.gameObject.tag = "PlayerAmmoX";
    37.             tlaser01.rotation = new Quaternion (0f, fwbw,0f,0f) ;
    38.         };
    39.     }
    40. }
    want that laser to rebound on shield on a random Y angle buuuuuuuuut it doesn't work, it only returns 180 as its angle, even when i designed it to be random...
     
  2. abysswolf

    abysswolf

    Joined:
    Oct 15, 2012
    Posts:
    62
    also tryed to get

    tlaser01.rotation = Quaternion.Inverse(tlaser01.rotation)

    and doesn't even change rotation