在unity3D中,我在运行时动态创建和销毁封装.我用空间来制造胶囊,用C来破坏.
我想创建多个对象并在时间上销毁多个对象.当我多次按下Space时,对象正在创建多个时间就好了.
但问题是,当我多次按C时,只有一个物体在摧毁.我怎样才能破坏多个物体?逐一.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DynamicCreate : MonoBehaviour
{
public GameObject caps;
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space))
{
createObject();
}
if (Input.GetKeyDown(KeyCode.C))
{
destroyObject();
}
}
private void createObject()
{
caps = GameObject.CreatePrimitive(PrimitiveType.Capsule);
}
public void destroyObject()
{
Destroy(caps);
}
}
Run Code Online (Sandbox Code Playgroud) 越过山丘时, NavmeshAgent 玩家与山坡不平行。在平面上它进展顺利。
下面是navMesh 和播放器的 图像属性https://ibb.co/fijmoV
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class SampleAgentScript : MonoBehaviour {
public Transform target ;
NavMeshAgent agent;
// private static bool start1=false , start2=false, start3;
// Use this for initialization
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
//if white button click moves to targer-1
agent.SetDestination(target.position);
}
}
Run Code Online (Sandbox Code Playgroud)