Kirish kurs ishining dolzarbligi



Download 1,52 Mb.
bet2/2
Sana11.07.2022
Hajmi1,52 Mb.
#776436
1   2
Bog'liq
SLATTTTTTT(3)

using UnityEngine; using System.Collections; public class Rocket : MonoBehaviour { // The fly speed (used by the weapon later) public float speed = 2000.0f; // explosion prefab (particles) public GameObject explosionPrefab; // find out when it hit something void OnCollisionEnter(Collision c) { // show an explosion // - transform.position because it should be // where the rocket is // - Quaternion.identity because it should // have the default rotation Instantiate(explosionPrefab, transform.position,

  • yaratishda biz Unity zarralarini allaqachon import qilganmiz va ular uchun biz uchun juda yaxshi bo'lgan Portlash effekti mavjud.
  • Shunday qilib, keling, standart aktivlar -> zarrachalar-> "Eski qism" lar ostidagi Loyiha maydonini ko'rib chiqamiz va Kichik portlash Prefab-ni Roketamiz skriptidagi Endi portlash vaqti keldi. Va yana birdamlik bizga yordam beradi. Biz loyihani Portlash Prefab uyasiga tortamiz, shunda quyidagicha ko'rinadi:Yana bir narsa: odatdagidek portlash yana va yana portlashi mumkin, shuning uchun loyiha maydonida Kichik portlash prefabsini tanlaymiz va "Bir zarba" variantini yoqamiz: Yana bitta narsa: odatdagidek portlash yana va yana portlashi mumkin. Loyiha hududidagi kichik portlash prefabsini tanlang va "Bir zarba" variantini yoqing:
  • Mayli, yana C # skriptini yaratamiz, bu safar uni Shut deb nomlaymiz. Ushbu skript har bir o'yinchi sichqonchani bosganida yangi Raketani tarqatishi kerak. Keyin uni oldinga uchish uchun Rigidbody's AddForce usulidan foydalaniladi: using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { // Rocket Prefab public GameObject rocketPrefab; // Update is called once per frame void Update () { // left mouse clicked? if (Input.GetMouseButtonDown(0)) { // spawn rocket // - Instantiate means 'throw the prefab into the game world' // - (GameObject) cast is required because unity is stupid // - transform.position because we want to instantiate it exactly // where the weapon is // - transform.parent.rotation because the rocket should face the // same direction that the player faces (which is the weapon's // parent. // we can't just use the weapon's rotation because the weapon is // always rotated like 45° which would make the bullet fly really // weird GameObject g = (GameObject)Instantiate(rocketPrefab, transform.position, transform.parent.rotation); // make the rocket fly forward by simply calling the rigidbody's // AddForce method // (requires the rocket to have a rigidbody attached to it) float force = g.GetComponent().speed; g.rigidbody.AddForce(g.transform.forward * force);
  • using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { // Rocket Prefab public GameObject rocketPrefab; // Update is called once per frame void Update () { // left mouse clicked? if (Input.GetMouseButtonDown(0)) { // spawn rocket // - Instantiate means 'throw the prefab into the game world' // - (GameObject) cast is required because unity is stupid // - transform.position because we want to instantiate it exactly // where the weapon is // - transform.parent.rotation because the rocket should face the // same direction that the player faces (which is the weapon's // parent. // we can't just use the weapon's rotation because the weapon is // always rotated like 45° which would make the bullet fly really // weird GameObject g = (GameObject)Instantiate(rocketPrefab, transform.position, transform.parent.rotation); // make the rocket fly forward by simply calling the rigidbody's // AddForce method // (requires the rocket to have a rigidbody attached to it) float force = g.GetComponent().speed; g.rigidbody.AddForce(g.transform.forward * force); } } }

E’TIBORINGIZ UCHUN RAHMAT


Download 1,52 Mb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish