Okay so I’m making a game that is like Kaboom, and I’m having a problem with making an instance of my bomb object appear.
Here’s the code for the bomb object it self:
`
using UnityEngine;
using System.Collections;
public class Bomb : MonoBehaviour
{
public int moveSpeed = 60;
Vector3 moveDirection = new Vector3(0,-1,0);
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Vector3 newPosition = moveDirection * (moveSpeed * Time.deltaTime);
transform.position = transform.position + newPosition;
if(newPosition.y > -40)
{
Destroy(transform.gameObject);
}
}
void OnCollision(Collision collision)
{
Destroy(transform.gameObject);
}
}
`
And I’m trying to get the enemy object to create a new instance of the bomb, here’s the enemy object’s code:
`using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour
{
public int moveSpeed = 40;
public bool isComputer = false;
Vector3 computerDirection = Vector3.right;
public bool onScreen = true;
public Transform bomb;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Vector3 newPosition = Vector3.zero;
newPosition = computerDirection * (moveSpeed * Time.deltaTime);
newPosition = newPosition + transform.position;
if(newPosition.x > 20)
{
newPosition.x = 20;
computerDirection.x *= -1;
}
else if(newPosition.x < -20)
{
newPosition.x = -20;
computerDirection.x *= -1;
}
transform.position = newPosition;
if(onScreen == true)
{
Transform newBomb = Instantiate(bomb,transform.position, transform.rotation) as Transform;
}
}
}
`
The thing that won’t work is when I’m trying to create a new instance of the bomb while the enemy object is on screen, after the original bomb object is destroyed.
Any ideas??