FPS Controller and Explosion?

I’m using the detonator framework and have an fps controller that can’t be affected by the explosion. I have written this script so far so that the player can be moved:

var targetObj : Transform;
var prefabContainer:Transform;
var proximity : float = 8;

function Update() {

    var dist = Vector3.Distance(targetObj.transform.position, transform.position);
  if (dist < proximity) {
    var instanceContain = Instantiate(prefabContainer, targetObj.transform.position, targetObj.transform.rotation);
    targetObj.transform.parent = instanceContain;

But unity doesn’t allow prefab objects to be parented. How do I set targetObj to be a specific item in the hierarchy and not a prefab?

found your problem


targetObj.transform.parent = instanceContain.transform;

sorry for the late reply I was quite busy
You can
1.Create a empty gameobject and child the player obj.Remove Charactercontroller .Add rigidbody ,Use rigidbody.velocity instead of CharacterController.Move to move the player


2.I havent tried this yet Add this to your player prefab

var exppos:Vector3;
var self:Transform;
var explode:boolean = false;
var minexp:float = 5.0;
var char:CharacterController;
var expspeed:float = 12;

function Explosion(pos:Vector3){
self = pos;
explode = true;

function update(){
if(Vector3.Distance(self.position,exppos) < minexp){//checking second time that if player's pos is less than minimu explosion distance
var direction = self.position - exppos;

char.Move(direction.normalized * expspeed * Time.deltaTime);

}else{explode = false;}
// your movement code

In your explosion script add this

   var pos:Vector3;

function Update(){
    var objs:Collider[] = 
    for(var:exp in objs){
    if(exp.transform.tag =="Player"){

Rate it if you like it