public void initCharacter(int courseID, int carId, int charID, float maxHP, float maxMP, float attackPower, float defense, float speed, float skillCD, int racerNum, bool isPlayer = false) { Debug.Log("generating char = " + carId); Vector3 position = courseList[courseID].getStartPositions()[racerNum + 1]; Quaternion rotation = Quaternion.Euler(0, courseList[courseID].getStartRotation().eulerAngles.y, 0); PathManager path = courseList[courseID].getPath(); Car car = Instantiate(characterList[carId], position, rotation).GetComponent <Car>(); CarStatus carStatus = car.GetComponent <CarStatus>(); MiniMapMark mark = Instantiate(miniMarkList[carId], position, rotation).GetComponent <MiniMapMark>(); if (charID != 0) { DestroyImmediate(car.GetComponent <N2OSkill>()); } if (charID != 1) { DestroyImmediate(car.GetComponent <TimeStopSkill>()); } if (charID != 2) { DestroyImmediate(car.GetComponent <CoinAttackSkill>()); } if (charID != 3) { DestroyImmediate(car.GetComponent <FlameSkill>()); } if (charID != 4) { DestroyImmediate(car.GetComponent <SpearSkill>()); } //init car params carStatus.attackInitialize(attackPower); carStatus.HPInitialize(maxHP); carStatus.MPInitialize(maxMP); carStatus.skillCDInitialize(skillCD); carStatus.setTopSpeed(basicTopSpeed * (1 + (speed / 1000f)));//speed = 100pt = 1.1times carStatus.defenseBase = defense; mark.transform.parent = miniMap.transform; marks[racerNum] = mark; racers[racerNum] = car; racersLength++; mark.transform.localPosition = new Vector3(0, 0, 0); mark.MyCar = car.transform; car.GetComponentInChildren <EnemyBarLookAt>().mainCameraTrans = backGroundCamera.transform; if (car.GetComponent <TimeStopSkill>() != null) { car.GetComponent <TimeStopSkill>().backGroundCamera = backGroundCamera; car.GetComponent <TimeStopSkill>().mainCamera = mainCamera; } if (isPlayer)//player { statImage.collector = car.GetComponent <ItemCollector>(); setCamera(car, skyBoxIdx); itemBtn.setCollector(car.GetComponent <ItemCollector>()); moveBtn.setPlayerCar(car); DestroyImmediate(car.gameObject.GetComponent <AIScript>()); // delete player car's ai script miniMap.GetComponent <MiniMapManager>().setCamTarget(mark.transform); } else { DestroyImmediate(car.gameObject.GetComponent <PlayerController>());// delete ai car's player script foreach (Camera cam in car.gameObject.GetComponentsInChildren <Camera>()) { // disable ai car's camera cam.gameObject.SetActive(false); } car.gameObject.GetComponent <AIScript>().path = path; } }