Search Unity

Is it possible to do on unity?

Discussion in 'Scripting' started by Ericmatheus, Oct 25, 2014.

  1. Ericmatheus

    Ericmatheus

    Joined:
    Aug 11, 2014
    Posts:
    68
    var pos;
    var timerepeat : float;
    function Start () {
    timerepeat =2;
    transform.position = Vector3 (56.02863,0.8328421,5.642716);
    InvokeRepeating ("active",timerepeat,timerepeat);
    }
    function Update () {
    }
    function OnCollisionEnter (collision : Collision ) {
    if (collision.gameObject.tag == "Bullet") {
    this.gameObject.SetActive (false);
    active ();
    }
    }
    function active () {
    if (!this.gameObject.activeSelf)
    this.gameObject.SetActive (true);
    }

    The script above is for an enemy that i did,it dies when receive one damage,i'm not using destroy
    What i want is:
    When the enemy dies,when the enemy SetActive change for false then active for true again but when active for true,the position gonna change and then if receive a damage again the postion change again and over and over again...
     
  2. Deleted User

    Deleted User

    Guest

    Ya very possible but why not just turn it onto a prefab and initiate at as your need it.
     
  3. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    Also recommend using raycasts in place of that sort of collision detection. I used your method for awhile, and very quickly ran into issues where the projectile would completely miss, even if the aim was perfect, just due to the nature of per-frame movement.
     
  4. Ericmatheus

    Ericmatheus

    Joined:
    Aug 11, 2014
    Posts:
    68
    Thank you everbody