i have an enemy cube which moves towards the player with this script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class enemyscript : MonoBehaviour {
public GameObject enemy;
public Text score;
int abc=1;
public float speed;
private Vector3 one = new Vector3(4.5f, 0.6f, 0f);
private Vector3 two = new Vector3(4.5f, 0.6f, 1f);
private Vector3 three = new Vector3(4.5f, 0.6f, 2f);
private Vector3 four = new Vector3(4.5f, 0.6f, -1f);
private Vector3 five = new Vector3(4.5f, 0.6f, -2f);
public Vector3 store;
public float st;
public float en;
private int i = 0;
bool xc = true;
Vector3 forwardRotationPoint;
Vector3 backRotationPoint;
Vector3 leftRotationPoint;
Vector3 rightRotationPoint;
Bounds bounds;
bool rolling;
bool and = true;
int a;
int lolipop;
private long dodgefrog;
double valuOfScore = 0;
private Vector3 act;
bool isThere = false;
void Start()
{
lolipop = 1;
dodgefrog = 0;
store = Gen(store);
enemy.transform.position = store;
bounds = GetComponent<MeshRenderer>().bounds;
forwardRotationPoint = new Vector3(0, -bounds.extents.y, bounds.extents.z);
backRotationPoint = new Vector3(0, -bounds.extents.y, -bounds.extents.z);
leftRotationPoint = new Vector3(-bounds.extents.x, -bounds.extents.y, 0);
rightRotationPoint = new Vector3(bounds.extents.x, -bounds.extents.y, 0);
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name.Equals("playerdup")){
Time.timeScale = 0;
}
}
void Update()
{
if(enemy.transform.position.x<=-4.7){
Destroy(enemy);
scorecontroller.scorevalue += 1;
generateEenemy.numberOfEnemies -= 1;
Debug.Log(generateEenemy.numberOfEnemies);
isThere = true;
int number = generateEenemy.numberOfEnemies;
if (number == 0)
{
(I DONT KNOW WHAT TO DO)
}
}
if (enemy.transform.position.x >= st && enemy.transform.position.x <= en && and)
{
Instantiate(enemy);(Somehow INSTANTIATING)
generateEenemy.numberOfEnemies += 1;
Debug.Log(generateEenemy.numberOfEnemies);
and = false;
}
if (rolling)
return;
StartCoroutine(Roll(leftRotationPoint));
}
private IEnumerator Roll(Vector3 rotationPoint)
{
Vector3 point = transform.position + rotationPoint;
Vector3 axis = Vector3.Cross(Vector3.up, rotationPoint).normalized;
float angle = 90;
float a = 0;
rolling = true;
and = true;
while (angle > 0)
{
a = Time.deltaTime * speed;
transform.RotateAround(point, axis, a);
angle -= a;
yield return null;
}
transform.RotateAround(point, axis, angle);
rolling = false;
}
public Vector3 Gen(Vector3 sam)
{
int posStart = Random.Range(0, 5);
if (posStart == 0)
{
sam = one;
}
else if (posStart == 1)
{
sam = two;
}
else if (posStart == 2)
{
sam = three;
}
else if (posStart == 3)
{
sam = four;
}
else if (posStart == 4)
{
sam = five;
}
return sam;
}
}
I (I DONT KNOW WHAT TO DO )
i want to instantiate the enemy, but when i do so , it instantiates it just where the previous enemy died or got destroyed.
In (SOMEHOW INSTANTIATING)
The cube generates at the correct position.
Pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeese Help
I have been trying to do this for like 2 weeks now.
I will reward the user with 20 reputation
PLEASE ANY HELP WOULD BE APPRECIATED.
THANKS!!