bool dealDamage( GameObject human, float damage ) { HealthComponent health = human.GetComponent<HealthComponent> (); HumanBehavior h = human.GetComponent<HumanBehavior> (); if( health == null ) { return true; } health.dealDamage( damage, gameObject ); if( health.isDead() ) { if( h != null && h.turnIntoRagdoll() ) { m_victimHead = human; foreach (Transform child in human.GetComponentsInChildren<Transform>()) { if (child.name == "Head") { m_victimHead = child.gameObject; break; } } } } return health.isDead (); }
void Start() { //Set a default position for the camera Nathan = GameObject.Find("Nathan"); humanScript = Nathan.GetComponent <HumanBehavior>(); CutSceneCamera = Nathan.transform.Find("cutScene").gameObject; TargetRoom = transform.position; originPos = transform.position; }
void OnCollisionEnter(Collision collision) { if (m_impactTarget == null) { // :BILL: rootColliderObject doesn't play well with nesting child to runtime parents. 10 17 2018 //note we aren't nested in a parent now, betcause SetParent position error. GameObject rootColliderObject = getRootObject(collision.gameObject); if (rootColliderObject.tag == "Human") { HumanBehavior hb = rootColliderObject.GetComponent <HumanBehavior>(); if (hb != null) { hb.handleBulletImpact(collision); } } else if (rootColliderObject.tag == "Zombie") { ZombieBehavior zb = rootColliderObject.GetComponent <ZombieBehavior>(); if (zb != null) { zb.handleBulletImpact(collision); } } if (rootColliderObject.GetComponent <HealthComponent>() != null) { m_impactTarget = collision.rigidbody; m_lifeTime = 0.25f; } /* * GameObject childColliderObject = getChildRootObject(collision.gameObject); * * if (childColliderObject.tag == "Human") { * HumanBehavior hb = childColliderObject.GetComponent<HumanBehavior> (); * if (hb != null) { * hb.handleBulletImpact (collision); * } * } else if (childColliderObject.tag == "Zombie") { * ZombieBehavior zb = childColliderObject.GetComponent<ZombieBehavior> (); * if (zb != null) { * zb.handleBulletImpact (collision); * } * } * * if (childColliderObject.GetComponent<HealthComponent> () != null ) { * m_impactTarget = collision.rigidbody; * m_lifeTime = 0.25f; * } */ } if (m_impactTarget == null) { Destroy(gameObject); } }
// Use this for initialization void Start () { behavior = gameObject.FindBehavior() as HumanBehavior; animator = gameObject.GetUnit().GetComponent <Animator>(); motor = behavior.motor as HumanMotor; // --- //motor.moveEvents.onThisMoveStart.AddListener (OnMoveStart); //motor.moveEvents.onThisMoveStop.AddListener (OnMoveStop); //motor.moveEvents.onThisSpeed.AddListener (OnThisSpeed); //behavior.attack.attackEvents.onAttackStart.AddListener (OnAttackStart); }
public override void Start(GameController gc) { playerBehavior = new HumanBehavior(playerShip, 1); gc.SpawnEntity(playerShip, "ship_blue"); enemyBehavior = new AiBehavior(enemyShip); gc.SpawnEntity(enemyShip, "ship_red"); collector += gc.uiController.ShowEntityHealth(playerShip, true); collector += gc.uiController.ShowEntityHealth(enemyShip, false); }
public override void Start(GameController gc) { firstPlayerBehavior = new HumanBehavior(firstPlayerShip, 1); gc.SpawnEntity(firstPlayerShip, "ship_blue"); secondPlayerBehavior = new HumanBehavior(secondPlayerShip, 2); gc.SpawnEntity(secondPlayerShip, "ship_red"); collector += gc.uiController.ShowEntityHealth(firstPlayerShip, true); collector += gc.uiController.ShowEntityHealth(secondPlayerShip, false); spawnCoro = gc.StartCoroutine(asteroidSpawner.Spawn(gc)); }
public override void Start(GameController gc) { input = new HumanBehavior(playerShip, 1); gc.SpawnEntity(playerShip, "ship_blue"); spawnCoro = gc.StartCoroutine(asteroidSpawner.Spawn(gc)); collector += gc.asteroidDestroyed.Listen(() => { if (playerShip.health.value > 0) { currentScore.value += 10; } }); collector += currentScore.Bind(score => gc.uiController.currentScore.text = "Score: " + score); collector += gc.uiController.ShowEntityHealth(playerShip, true); }
public void SpawnHuman() { // Get reference to point List <Transform> spawnpoints = new List <Transform>(); foreach (HumanSpawn hs in FindObjectsOfType <HumanSpawn>()) { spawnpoints.Add(hs.transform); } // Spawn the actor HumanBehavior human = Instantiate(Library.instance.humanPrefab).GetComponent <HumanBehavior>(); // If some spawnPoints has been found if (spawnpoints.Count > 0) { human.transform.position = spawnpoints[Random.Range(0, spawnpoints.Count)].position; } }
public bool turnIntoRagdoll() { UnityEngine.AI.NavMeshAgent n = GetComponent <UnityEngine.AI.NavMeshAgent>(); Animator a = GetComponent <Animator>(); HumanBehavior h = GetComponent <HumanBehavior>(); ZombieBehavior z = GetComponent <ZombieBehavior>(); RagdollHelper r = GetComponent <RagdollHelper> (); HealthComponent hc = GetComponent <HealthComponent>(); setCollidersEnabled(true); bool result = false; if (n != null && a != null && r != null && a.enabled) { r.ragdolled = true; m_time = 0.0f; if (h != null) { h.die(); if (!hc.wasKilledBy(null)) { m_postProcessHumanRagdoll = 1u; } result = true; } else if (z != null) { if (hc.isDead()) { z.die(); } result = true; } n.enabled = false; } return(result); }
public void TriggerSteering() { HumanBehavior.SetState(1); stateText.text = "Steering"; }
public void TriggerKenimatic() { HumanBehavior.SetState(0); stateText.text = "Kenimatic"; }
// Update is called once per frame void Update() { if (!m_initializedRagdoll && GetComponent <Animator>() != null) { m_ragdoll = MainGameManager.instance.getRagdollTemplate(); m_initializedRagdoll = true; Component[] transforms = GetComponentsInChildren <Transform> (); string[] boneNames = { "Hips", "LeftUpLeg", "LeftLeg", "LeftFoot", "RightUpLeg", "RightLeg", "RightFoot", "LeftArm", "LeftForeArm", "RightArm", "RightForeArm", "Spine", "Head" }; GameObject[] boneObjects = { null, null, null, null, null, null, null, null, null, null, null, null, null }; Bone[] connections = { Bone.None, Bone.Hips, Bone.LeftUpLeg, Bone.LeftLeg, Bone.Hips, Bone.RightUpLeg, Bone.RightLeg, Bone.Spine, Bone.LeftArm, Bone.Spine, Bone.RightArm, Bone.Hips, Bone.Spine }; Component[] sphereCollidersInRagdollTemplate = m_ragdoll.GetComponentsInChildren <SphereCollider>(); Component[] boxCollidersInRagdollTemplate = m_ragdoll.GetComponentsInChildren <BoxCollider>(); Component[] capsuleCollidersInRagdollTemplate = m_ragdoll.GetComponentsInChildren <CapsuleCollider>(); Component[] rigidBodiesInRagdollTemplate = m_ragdoll.GetComponentsInChildren <Rigidbody>(); Component[] characterJointsInRagdollTemplate = m_ragdoll.GetComponentsInChildren <CharacterJoint>(); foreach (Transform t in transforms) { // collect game objects that we need reference to for the joint components for (int i = 0; i < boneNames.Length; ++i) { if (t.gameObject.name == boneNames[i]) { boneObjects[i] = t.gameObject; break; } } // handbone for humans if (t.gameObject.name == "RightHand") { HumanBehavior hb = GetComponent <HumanBehavior> (); if (hb != null) { hb.handBone = t; } } // copy different collider components foreach (SphereCollider c in sphereCollidersInRagdollTemplate) { if (t.gameObject.name == c.gameObject.name) { ComponentCopyHelper.GetCopyOf <SphereCollider>(t.gameObject.AddComponent <SphereCollider>(), c); break; } } foreach (BoxCollider c in boxCollidersInRagdollTemplate) { if (t.gameObject.name == c.gameObject.name) { ComponentCopyHelper.GetCopyOf <BoxCollider>(t.gameObject.AddComponent <BoxCollider>(), c); break; } } foreach (CapsuleCollider c in capsuleCollidersInRagdollTemplate) { if (t.gameObject.name == c.gameObject.name) { ComponentCopyHelper.GetCopyOf <CapsuleCollider>(t.gameObject.AddComponent <CapsuleCollider>(), c); break; } } // copy rigid bodies foreach (Rigidbody c in rigidBodiesInRagdollTemplate) { if (t.gameObject.name == c.gameObject.name) { ComponentCopyHelper.GetCopyOf <Rigidbody>(t.gameObject.AddComponent <Rigidbody>(), c); break; } } // copy joints foreach (CharacterJoint c in characterJointsInRagdollTemplate) { if (t.gameObject.name == c.gameObject.name) { CharacterJoint joint = ComponentCopyHelper.GetCopyOf <CharacterJoint>(t.gameObject.AddComponent <CharacterJoint>(), c); joint.connectedBody = null; for (int i = 0; i < boneNames.Length; ++i) { if (t.gameObject.name == boneNames[i]) { joint.connectedBody = boneObjects[(int)connections[i]].GetComponent <Rigidbody>(); break; } } break; } } } gameObject.AddComponent <RagdollHelper>(); } }
private void Awake() { player = new Controller(); //Assign light variables to proper objects in scene lightSwitch = GameObject.FindGameObjectWithTag("Lights"); worldLighting = GameObject.FindGameObjectWithTag("EnvironmentLights"); backUpLighting = GameObject.FindGameObjectWithTag("BackUpLights"); lightScript = lightSwitch.GetComponent <LightScript>(); //lightCooldown = 10f; lightEnable = true; //Assign gramophone variables to proper objects in scene gramophone = GameObject.FindGameObjectWithTag("Gramophone"); worldMusic = GameObject.FindGameObjectWithTag("WorldMusic"); musicScript = gramophone.GetComponent <GramophoneScript>(); //musicCooldown = 10f; musicEnable = true; //Assign painting variables to proper objects in scene painting = GameObject.FindGameObjectWithTag("Painting"); paintScript = painting.GetComponent <PaintingScript>(); //paintCooldown = 15f; paintEnable = true; prop = GameObject.FindGameObjectWithTag("Prop"); propScript = prop.GetComponent <PropScript>(); //Assign player numbers and colors playernum = numplayers; numplayers++; //Add by Guanchen Liu //Assign nathan Nathan = GameObject.Find("Nathan"); humanScript = Nathan.GetComponent <HumanBehavior>(); currentItem = selectedItem.None; currentCond = ghostCond.None; mainCamera = GameObject.Find("MainCamera"); sc = mainCamera.GetComponent <CameraControl>(); UI = UIManager.instance.gameObject; var UICoolDown = UI.transform.Find("CoolDown").gameObject; // lightImage = UICoolDown.transform.GetChild(0).GetComponent<Image>(); // musicImage = UICoolDown.transform.GetChild(1).GetComponent<Image>(); // paintImage = UICoolDown.transform.GetChild(2).GetComponent<Image>(); player.Gameplay.Grabbing.canceled += context => ReleaseObject(); if (playernum == 0) { GameObject temp = GameObject.Find("Ghost_1"); transform.position = temp.transform.position; Destroy(temp); mesh.material = color1; gameObject.name = "Ghost_1"; } if (playernum == 1) { GameObject temp = GameObject.Find("Ghost_2"); transform.position = temp.transform.position; Destroy(temp); mesh.material = color2; gameObject.name = "Ghost_2"; backUpLighting.gameObject.SetActive(false); var UIScript = UI.GetComponent <UIManager>(); Time.timeScale = 1.0f; UIScript.playStartImage(); } var allGhost = GameObject.FindGameObjectsWithTag("Ghost"); choreManger = GameObject.Find("ChoreManger").GetComponent <ChoreManger>(); }
GameObject GenerateUMA(string name) { // Create a new game object and add UMA components to it GameObject GO = new GameObject(name); GO.transform.position = this.transform.position; //parentAtPosition(GO); umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>(); umaDynamicAvatar.animationController = animationController; GO.AddComponent <RagdollCreatorTest>(); if (name.Contains("Zombie")) { ZombieBehavior zbh = GO.AddComponent <ZombieBehavior> (); zbh.speedMultiplier = Random.Range(0.5f, 2.5f); GO.tag = "Zombie"; GameObject[] zombies = GameObject.FindGameObjectsWithTag("Zombie"); GO.name = "Zombie" + zombies.Length; } else { HumanBehavior hb = GO.AddComponent <HumanBehavior> (); GO.tag = "Human"; // GameObject[] humans = GameObject.FindGameObjectsWithTag("Human"); //GO.name = "Human" + humans.Length; } GO.AddComponent <UnityEngine.AI.NavMeshAgent> (); GO.AddComponent <HealthComponent> (); // Initialize Avatar and grab a reference to its data component umaDynamicAvatar.Initialize(); umaData = umaDynamicAvatar.umaData; // Attach our generator umaDynamicAvatar.umaGenerator = generator; umaData.umaGenerator = generator; // Set up slot Array umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots]; // Set up our Morph references umaDna = new UMADnaHumanoid(); umaTutorialDNA = new UMADnaTutorial(); umaData.umaRecipe.AddDna(umaDna); umaData.umaRecipe.AddDna(umaTutorialDNA); if (name.Contains("Female")) { CreateFemale(); } else { CreateMale(); } // Generate our UMA setupDna(umaDna); umaDynamicAvatar.UpdateNewRace(); if (name.Contains("Human")) { if (name.Contains("Female")) { GO.name = createName("Female"); } else { GO.name = createName("Male"); } } return(GO); }