GetComponentsInChildren形成的数组包含当前游戏物体transform,不想删除当前游戏物体时,用if语句判断一下,children[i]是不是当前游戏物体,不是,就要销毁。
children[i]是transform组件,销毁属于game object中的方法,所以要访问到游戏物体需要在children[i]后面加.gameobject。
GetComponentsInChildren形成的数组包含当前游戏物体transform,不想删除当前游戏物体时,用if语句判断一下,children[i]是不是当前游戏物体,不是,就要销毁。
children[i]是transform组件,销毁属于game object中的方法,所以要访问到游戏物体需要在children[i]后面加.gameobject。
三种循环销毁子物体
数学运算符
+-*/%
赋值运算符
= += -= *=/=%=
a+=b ==> a=a+b
比较运算符
> >= < <= == !=
逻辑运算符
&&逻辑与
||逻辑或
!取反
哈哈,这个对象不是我的女朋友
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyGame;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameData gamedata;
}
// Update is called once per frame
void Update()
{
}
}
namespace MyGame
{
class GameData
{
}
}
实例化类名
类名.方法();
类的定义,声明,创建.
有返回值的方法:
参数
enum Roletype{
Mag,
Solder,
Wizard}
方法中可以调用定义的类型
RoleType rt= RoleType.Mag;
类名,习惯大写.
csharp名就是类名
返回值 方法名(参数){方法体}
声明变量的方法.
方法的作用: 把重复的代码放到方法里面,可以方便调用.
for(int i=1;i<=10,i++)
{
print("创建了一个敌人"+i)
}
for(int i=0;i<10,i++)
{
print("创建了一个敌人"+i)
}
声明数组第一种方式:
int[] hps={100,20,60,80,90};
int[] hps=null;
int[] hps={};
声明数组第二种方式:
长度为10的数组
int[] hps=new int[10];
声明数组第三种方式:
int[] hps =new int[5]{100,20,60,80,90};
数组:
类型[] 数组名={数组值}
int[] hps={100,20,80,90,30};
索引访问数据0
数组名[];
pring(hps[1]);