Answer the question
In order to leave comments, you need to log in
How to make the destruction of two objects after the expiration of time on Unity?
The code on idea should request objects which on a touch with each other - are destroyed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AirUlt : MonoBehavior
{
public GameObject Ammo;
public GameObject Enemy;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter()
{
if (Trigger("Ammo") == Collision("Enemy" ))
Destroy(GameObject(Ammo), 7f);
}
}
{
Destroy(GameObject(Enemy), 7f);
}
But in the end it gives me errors
Assets\Scripts\AirUlt.cs(22,13): error CS0103: The name 'Trigger' does not exist in the current context
Assets\Scripts\AirUlt.cs(22,32): error CS1955 : Non-invocable member 'Collision' cannot be used like a method.
Assets\Scripts\AirUlt.cs(24,21): error CS1955: Non-invocable member 'GameObject' cannot be used like a method.
Assets\Scripts\AirUlt.cs(25,21): error CS0103: The name 'GameObjcet' does not exist in the current context
How do I fix them?
Answer the question
In order to leave comments, you need to log in
If it is fundamental to do just that, then you need to understand that there should be only one bullet in the scene, otherwise this object that "controls objects in the air" will not understand what to delete. Also, in order for the collision to "occur", there must be a collider on the objects. I would advise you to hang the script directly on a bullet or an enemy and already check the collision in them, which will be a plus in terms of the fact that you can, for example, spawn bullets from a prefab with a script. Then the code will be in the pool like this.
void OnCollisionEnter(Collision col){
if (col.gameObject.name=="enemy") {
Destroy (col.gameObject, 7f); //удаляем врага с !КОТОРЫМ! столкнулись.
}
Destroy (gameObject, 7f); //удаляем нашу пулю если она в что либо врезалась.
}
void Update(){
Destroy (gameObject, 10f); //удаляем нашу пулю если она никуда не врезалась и улетела в далёкие края.
}
How to fix the problem
and what is wrong?
like you know about collisions and triggers.
how to delete objects in a course.
about checking by tag - you also seem to know.
if this code is not a copy-paste, then describe what exactly does not work and what it swears at.
from what caught my eye
if (Enemi.tag == "UltA")
is that how the tag sees?? Enemi is a collision. you need to take a gemobject or a collider from her
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question