Help with "Kaboom" game programming, Unity first time user.

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??

I don’t understand your question and what your problem is by your explanations. I don’t even know the game before (so i had to google first).

The only thing that doesn’t make sense is that if your bomb’s movedirection is (0,-1,0), this condition doesn’t make any sense: if(newPosition.y > -40)

Since the movedirection is negative the position can only get smaller. So either the position is greater than -40 from the beginning on so the bomb is destroyed in the first frame, or the bomb starts below -40 so the condition never can become true since the position is getting smaller.

I guess you have messed up your condition. Most people don’t understand that -50 < -40

Beside that i can’t see major mistakes in your code without knowing the actual issue.