2017-08-30 4 views
0

私は2Dプラットフォームゲームの上司を作っています。大きなボスが死んだときに小さなボスをインスタンス化する際に問題が発生しました。だから私はBossHealthManagerと呼ばれるスクリプトを持っており、その上司の健康が< = 0に達すると、2人の小さなボスをインスタンス化します。しかし、大きなボスを殺して2人の小さいボスをインスタンス化したとき、彼らはその場で揺れ続け、決して動かなかった。すべてのボスには移動スクリプトが添付されています。だから私は2人の小さなボスが動かない理由について困惑している。Unity2D、インスタンス化されたオブジェクトが揺れ続ける

public class BossHealthManager : MonoBehaviour { 

public int enemyHealth; 

public GameObject deathEffect; 

public int pointsOnDeath; 

public GameObject bossPrefab; 

public float minSize; 

// Use this for initialization 
void Start() 
{ 

} 

// Update is called once per frame 
void Update() 
{ 
    if (enemyHealth <= 0) 
    { 
     Instantiate(deathEffect, transform.position, transform.rotation); 
     ScoreManager.AddPoints(pointsOnDeath); 

     if(transform.localScale.y > minSize) 
     { 
      GameObject clone1 = Instantiate(bossPrefab, new Vector3(transform.position.x + 0.5f, transform.position.y, transform.position.z), transform.rotation) as GameObject; 

      GameObject clone2 = Instantiate(bossPrefab, new Vector3(transform.position.x - 0.5f, transform.position.y, transform.position.z), transform.rotation) as GameObject; 

      clone1.transform.localScale = new Vector3(transform.localScale.y * 0.5f, transform.localScale.y * 0.5f, transform.localScale.z); 
      clone1.GetComponent<BossHealthManager>().enemyHealth = 10; 

      clone2.transform.localScale = new Vector3(transform.localScale.y * 0.5f, transform.localScale.y * 0.5f, transform.localScale.z); 
      clone2 .GetComponent<BossHealthManager>().enemyHealth = 10; 
     } 

     Destroy(gameObject); 
    } 


} 

public void giveDamage(int damageToGive) 
{ 
    enemyHealth -= damageToGive; 
    // play whatever audio attached to the gameobject 
    GetComponent<AudioSource>().Play(); 
} 

}

これは私の上司は私の動きスクリプトです:助けを

public class BossPatrol : MonoBehaviour { 

public float moveSpeed; 
public bool moveRight; 

// wall check 
public Transform wallCheck; 
public float wallCheckRadius; 
public LayerMask whatIsWall; 
private bool hittingWall; 

// edge check 
private bool notAtEdge; 
public Transform edgeCheck; 

private float ySize; 

void Start() 
{ 
    ySize = transform.localScale.y; 
} 

void Update() 
{ 
    hittingWall = Physics2D.OverlapCircle(wallCheck.position, wallCheckRadius, whatIsWall); 

    notAtEdge = Physics2D.OverlapCircle(edgeCheck.position, wallCheckRadius, whatIsWall); 

    if (hittingWall || !notAtEdge) 
    { 
     moveRight = !moveRight; 
     //Debug.Log("hit"); 
    } 

    // moving right 
    if (moveRight == true) 
    { 
     transform.localScale = new Vector3(-ySize, transform.localScale.y, transform.localScale.z); 
     GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y); 
    } 
    else if (moveRight == false) 
    { 
     transform.localScale = new Vector3(ySize, transform.localScale.y, transform.localScale.z); 
     GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y); 
    } 
} 
} 

Big Boss

Smaller Bosses

ありがとう!

+0

上の補間オプションを選択して、アンチェックdidntの – ryeMoss

+0

@ryemoss更新ボスの移動のためのスクリプトを投稿してください! – Daaenerys

+1

ああ問題が見つかりました!私はKinematicのオプションであることを確認しなかった – Daaenerys

答えて

0

ユーザは、プレハブのRigidbodyでKinematicオプションのチェックを外すことで、問題を解決しました。コメントを引用

ああ、私は問題を発見しました!私は問題を解決したものを私のために動オプション

関連する問題