public void OnCollisionEnter(Collision collision) { if (m_bDead == true) { return; } //if (StaticVars.b_isGameOver == false) //{ if (collision.transform.tag == "Rocket") { Rocket rocket = collision.gameObject.GetComponent <Rocket>(); float f_damege = rocket.getDamage(); //m_fHP = Mathf.Clamp(m_fHP - f_damege, 0, m_fMaxHP); m_fHP -= f_damege; TAudioMgr.Instance.PlayEffect("explosion"); Debug.Log(m_fHP.ToString()); GameObject obj = TPrefabMgr.Instance("Blood", "Blood", collision.transform.position.x, collision.transform.position.y, collision.transform.position.z); // b_isGotHit = true; if (m_fHP <= 0) { m_fHP = 0.0f; //fpc.m_iScore += 10; //Debug.Log(fpc.m_iScore.ToString()); m_bDead = true; TAudioMgr.Instance.PlayEffect("zo_pain"); m_Animation.CrossFade(m_DieAnimation.name); Invoke("DestroyNow", 10.0f); /* * GameObject obj_aiPrefab = GameObject.Instantiate(m_Ragdoll, transform.position, transform.rotation) as GameObject; * * float f_force = 1000; * Rigidbody[] a_rigid = obj_aiPrefab.GetComponentsInChildren<Rigidbody>(); * * foreach (Rigidbody r in a_rigid) * { * r.AddExplosionForce(f_force, rocket.transform.position, 100.0f); * } * GameObject.Destroy(transform.parent.gameObject); */ } } //} }
void GetPosition(Vector3 pos) { Ray ray = Camera.main.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100.0f)) { if (hit.transform.tag == "Item") { GameObject obj = TPrefabMgr.Instance("CharEffect4", "CharEffect4", hit.point.x, hit.point.y, hit.point.z); //Destroy(hit.transform.gameObject, 0.2f); } GameObject obj2 = TPrefabMgr.Instance("CharEffect4", "CharEffect4", hit.point.x, hit.point.y, hit.point.z); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (m_Animation.isPlaying == false) { m_Fpc.m_iBullet -= 1; m_Animation.CrossFade(m_Shoot.name, 0.1f); TAudioMgr.Instance.PlayEffect("shot1"); Transform GunfirePos = transform.Find("GunFirePos"); GameObject obj = TPrefabMgr.Instance("Shot", "Shot", GunfirePos.transform.position.x, GunfirePos.transform.position.y, GunfirePos.transform.position.z); } } }
/* * private void PutTile(int iX, int iY, int iZ) * { * GameObject tile = TPrefabMgr.Instance("Tile1", "Tile1", iX, iY, iZ); * Vector3 objectScl = Vector3.Scale(tile.transform.localScale, new Vector3(c_fTileScale, c_fTileScale, 1.0f)); * tile.transform.localScale = objectScl; * } */ public void BoardInit() { xSize = ySize = 9; // map size _map = new BoardHolder[xSize, ySize]; //_map init for (int i = 0; i < ySize; i++) { for (int j = 0; j < xSize; j++) { _map[i, j] = new BoardHolder(); } } //tile set up bool isLight = true; for (int i = 0; i < ySize; i++) { if (ySize % 2 == 0) { if (isLight == true) { isLight = false; } else { isLight = true; } } for (int j = 0; j < xSize; j++) { if (isLight == true) { _grassLight.transform.position = new Vector3(j * c_nTileLength, 0, i * c_nTileLength); _map[i, j].objList.Add(GameObject.Instantiate(_grassLight)); isLight = false; } else { _grassDark.transform.position = new Vector3(j * c_nTileLength, 0, i * c_nTileLength); _map[i, j].objList.Add(GameObject.Instantiate(_grassDark)); isLight = true; } } } // for statement //int iX = 0; int iY = 0; int iZ = 10; TextAsset data = Resources.Load("stage1", typeof(TextAsset)) as TextAsset; StringReader sr = new StringReader(data.text); // 먼저 한줄을 읽는다. string source = sr.ReadLine(); string[] values; // 쉼표로 구분된 데이터들을 저장할 배열 (values[0]이면 첫번째 데이터 ) while (source != null) { values = source.Split(','); // 쉼표로 구분한다. 저장시에 쉼표로 구분하여 저장하였다. if (values.Length == 0) { sr.Close(); return; } for (int i = 0; i < values.Length; i++) { //0: outer wall, 1:tree, 2:emptyspace, 3:climber, 4:fire, 5:fireman string objname = ""; if (values[i].Equals("0")) { //objname = "OuterWall1"; continue; } else if (values[i].Equals("1")) { //PutTile(iX + i, iY, iZ); objname = "Tree1"; } else if (values[i].Equals("2")) { //PutTile(iX + i, iY, iZ); continue; } else if (values[i].Equals("3")) { //PutTile(iX + i, iY, iZ); objname = "Climber"; } else if (values[i].Equals("4")) { //PutTile(iX + i, iY, iZ); //objname = "Fire"; continue; } else if (values[i].Equals("5")) { //PutTile(iX + i, iY, iZ); objname = "Fireman"; } GameObject obj = TPrefabMgr.Instance(objname, objname, ((i - 1) * c_nTileLength) - (c_nTileLength / 2), iY, (iZ * c_nTileLength) - (c_nTileLength / 2)); Vector3 objectScale = Vector3.Scale(obj.transform.localScale, new Vector3(c_fTileScale, c_fTileScale, c_fTileScale)); obj.transform.localScale = objectScale; } source = sr.ReadLine(); // 한줄 읽는다. iZ--; } /* * xSize = ySize = 8; // map size * _map = new BoardHolder[xSize, ySize]; * * //_map init * for (int i = 0; i < ySize; i++) * for (int j = 0; j < xSize; j++) * _map[i,j] = new BoardHolder (); * * //tile set up * bool isLight = true; * for (int i = 0; i < ySize; i++) { * if (ySize % 2 == 0) { * if (isLight == true) * isLight = false; * else * isLight = true; * } * * for (int j = 0; j < xSize; j++) { * * * if (isLight == true) { * _grassLight.transform.position = new Vector3 (j * 14, 0, i * 14); * _map[i,j].objList.Add(GameObject.Instantiate (_grassLight)); * isLight = false; * } else { * _grassDark.transform.position = new Vector3 (j * 14, 0, i * 14); * _map[i,j].objList.Add(GameObject.Instantiate (_grassDark)); * isLight = true; * } * } * * } // for statement * * * // Determining firefighter's starting point. * List<int> charPositionNumbers = new List<int>(); * charPositionNumbers = GetRandomNumbers(0, xSize, _character._fireMans.Length, null); * charPositionNumbers.Sort (); * * int cnt=0; * charPositionNumbers.ForEach (item => { * * _character._charTextures[cnt].transform.position = new Vector3( item * 14 -7, 0, 7); * _character._charTextures[cnt].transform.localScale = new Vector3( 4,4,4); * _character._fireMans[cnt] = GameObject.Instantiate(_character._charTextures[cnt]); * cnt++; * }); * * * //tree random set up * List<int> treePositionNumbers = new List<int>(); * int mapArea = xSize * ySize - 1; * treePositionNumbers = GetRandomNumbers(0, mapArea, mapArea / 2, charPositionNumbers); * treePositionNumbers.Sort (); * * * treePositionNumbers.ForEach (item => { * int x = item % xSize; * int y = item / xSize; * int ranNum = UnityEngine.Random.Range(0,3); * _tree[ranNum].transform.position = new Vector3( (x)*14-7, 0, (y)*14 + 7); * _tree[ranNum].transform.localScale = new Vector3( 2,2,2); * _map[x, y].objList.Add(GameObject.Instantiate(_tree[ranNum])); * }); * * */ } // BoardInit
void Update() { if (m_bDead == true) { return; } if (Input.GetMouseButtonDown(0)) { if (m_PlayerShotGun.m_Animation.isPlaying == false) { // Create a vector at the center of our camera's viewport Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f)); // Declare a raycast hit to store information about what our raycast has hit RaycastHit hit; // Check if our raycast has hit anything if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange)) { if (hit.transform.tag == "Zombie") { EnemyMgr zomb = hit.collider.GetComponent <EnemyMgr>(); if (zomb.Equals(this)) { zomb.m_fHP -= 50; TAudioMgr.Instance.PlayEffect("zo_hit"); Debug.Log(zomb.m_fHP.ToString()); GameObject obj = TPrefabMgr.Instance("Blood", "Blood", hit.point.x, hit.point.y, hit.point.z); } } if (m_fHP <= 0.0f && m_bDead == false) { //fpc.m_iScore += 10; //Debug.Log(fpc.m_iScore.ToString()); m_bDead = true; TAudioMgr.Instance.PlayEffect("zo_pain"); m_Animation.CrossFade(m_DieAnimation.name); Invoke("DestroyNow", 10.0f); } //int a = 1; //// Set the end position for our laser line //laserLine.SetPosition(1, hit.point); //// Get a reference to a health script attached to the collider we hit //ShootableBox health = hit.collider.GetComponent<ShootableBox>(); //// If there was a health script attached //if (health != null) //{ // // Call the damage function of that script, passing in our gunDamage variable // health.Damage(gunDamage); //} //// Check if the object we hit has a rigidbody attached //if (hit.rigidbody != null) //{ // // Add force to the rigidbody we hit, in the direction from which it was hit // hit.rigidbody.AddForce(-hit.normal * hitForce); //} } } } if ((m_Player != null) && (m_fHP > 0)) { //if (StaticVars.b_isGameOver == false) //{ Vector3 vPos = m_Player.position; vPos.y += 1.0f; Vector3 vRocketDirection = (vPos - transform.position).normalized; // 조준을 시작한 상태가 아니라면 추적, if (Shoot(vRocketDirection)) { Run(); } else { // 웨이포인트로부터 특정 거리 이상 떨어져 있는지 확인 // m_fWaypointDistance 이상 떨어져 있으면 추적이나 공격을 멈추고 // 웨이포인트로 돌아간다. if (m_WayPoint.AwayFromWaypoint(transform, m_fWaypointDistance)) { m_bAiming = false; m_bRun = false; } } if (!m_bAiming) { NormalMove(vRocketDirection); } else { AttackMove(vRocketDirection); } //} //else //{ // m_Animation.CrossFade(m_IdleAnimation.name); //} } }