当前位置:网站首页>Test questions and some space wars
Test questions and some space wars
2022-04-23 03:22:00 【C # primary advanced】
1. The necessary conditions for an object to collide ?
Both objects must have colliders (Collider), One of the objects must also have Rigidbody rigid body , And it must be a moving object with Rigidbody Script can detect collision .
2.Unity3d The difference between Collider and trigger in ?
The method is different
Is Trigger Check or not
Can penetrate and cannot penetrate
The collider is the carrier of the trigger , The trigger is just an attribute of the collider . When Is Trigger=false when , The collider triggers collisions based on the physics engine , Produce the effect of collision , You can call OnCollisionEnter/Stay/Exit function ; When Is Trigger=true when , Collider ignored by physics engine , No collision effect , You can call OnTriggerEnter/Stay/Exit function . If you want to detect the contact of an object and don't want collision detection to affect the movement of an object or whether an object passes through an area in space, you can use a trigger
3. sketch prefab Usefulness ?
Presupposition : Repeated use Instantiate when the game is running ,prefab It's like a template , For the material you already have 、 Script 、 Parameter to make a default configuration , For future modification , meanwhile prefab The packaged content simplifies the export operation , Facilitate team communication .
4.Unity3d Scripts have a relatively complete life cycle from wake-up to destruction , Please list some of the system's own
Important methods ?
Awake——>OnEnable–>Start——>Update——>FixedUpdate——>LateUpdate——>OnGUI——>OnDisable——>OnDestroy
Space war needs
- Technical points
- Mathf class 、Transform class 、Time class 、GameObject class 、Vector3 class 、 Random class
- Keyboard events
- particle system
- Audio
- UGUI
- collision detection Saturday test
- coroutines
- The destruction
- clone
- Mouse events
- Star Management
-
- use Quad Make
- With two Quad Splicing into
- The stars circle and roll
-
- Our aircraft Management
-
- Control the movement through the keyboard
- Click the left mouse button to fire bullets
- There is a sound playing when the bullet is fired
- Jet effect at the tail of the plane
-
- Our bullet Management
-
- Bullets fly
- Hit a meteorite or enemy aircraft to reduce the opponent's HP , Destroy yourself
- If you don't hit a meteorite or an enemy plane after cloning , Hit the edge Collider and destroy
-
- Enemy meteorite Management
-
- Program started 3 Clone in seconds 3 individual , Then every 6 Second clone three more
- The meteorite rotates itself
- The bullets will be destroyed automatically when they encounter our prescription , Accompanied by explosion sound and explosion effects
-
- Enemy aircraft management
-
- Program started 8 Clone in seconds 3 individual , Then every 8 Second clone three more
- every other 1 Fire a bullet in seconds
- When life is 0 Time to destroy , Accompanied by explosion sound and explosion effects
-
- Enemy bullet management
-
- Bullets fly
- Hitting our aircraft will reduce the HP of our aircraft , Destroy yourself
- If you don't shoot our plane after cloning , Hit the edge Collider and destroy
-
- Points and health management
-
- Points are increased by destroying meteorites and enemy aircraft
- Health decreases as the enemy shoots at us , The duty of 0 When the game is over
-
register 、 Sign in 、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BG : MonoBehaviour {
public float speed;
Vector3 startPos;
void Start () {
startPos = transform.position;
}
// Update is called once per frame
void Update () {
float pos = Mathf.Repeat(speed*Time .time ,30f);
transform.position = startPos + Vector3.back * pos;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerShip : MonoBehaviour {
public float speed;
Rigidbody r;
public float fx;// Offset
public float xMax, xMin, zMax, zMin;
public GameObject bullet;// The bullet body
public Transform bulletpos;// Bullet firing position
public float shotSpace;// The interval between bullets (0.25)
private float nextShot; // Next launch time
public GameObject playerEx;
void Start () {
r = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
move();
Fire();
}
void Fire()
{
if (Input .GetButtonDown("Fire1")&&Time.time>nextShot)
{
nextShot = Time.time + shotSpace;
// Bullet cloning
Instantiate(bullet, bulletpos.position,Quaternion.identity );//bulletpos.rotation
}
}
private void move()
{
float h = Input.GetAxis("Horizontal") * speed;//*Time.deltaTime
float v = Input.GetAxis("Vertical") * speed;
Vector3 pos = new Vector3(h, 0, v);
r.velocity = pos;
// Aircraft rotation
r.rotation = Quaternion.Euler(0, 0, r.velocity.x * (-1) * fx);//-1 Indicates the correct direction
// Set boundaries
float x = Mathf.Clamp(r.position.x, xMin, xMax);
float z = Mathf.Clamp(r.position.z, zMin, zMax);
r.position = new Vector3(x, 0.3f, z);
}
void OnTriggerEnter(Collider other)
{
// Hit the bullet of the enemy plane , Enemy planes flying in and out , Meteorite
if (other.CompareTag("Enemy") || other.CompareTag("EnemyBullet")||other .CompareTag("EnemyShip"))
{
GM.instance.playerLife--;// Blood loss
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GM : MonoBehaviour {
public static GM instance;
public GameObject[] yunShi;// Three different types of meteorite presets
public GameObject[] enemy;
public int playerLife = 10;// Player health
public int enemyLife = 5;
public int score = 0;// fraction
public Text Hp;// Blood volume text
public Text ScoreTxt;// Score text
public GameObject GameOver;// Game ending screen
void Start()
{
instance = this;
StartCoroutine("SpwanEnemy");
}
void Update()
{
Hp.text = playerLife.ToString();
ScoreTxt.text = score.ToString();
if (playerLife <=0)
{
GameOver.SetActive(true);// Show the end of the game
Time.timeScale = 0;// Game pause
}
}
IEnumerator SpwanEnemy()
{
yield return new WaitForSeconds(3f);// Game begins 3 Seconds later
while (true)
{
for (int i = 0; i < yunShi .Length; i++)
{
// The location and species of cloned meteorites are random
int r = Random.Range(0, yunShi.Length);
float x = Random.Range(6.7f, -6.7f);
float z = Random.Range(-18f,-10f);
Instantiate(yunShi[r], new Vector3(x, 0.3f, z), Quaternion.identity);
}
for (int j = 0; j < enemy.Length; j++)
{
int f = Random.Range(0, enemy.Length);
float xx = Random.Range(6.7f, -6.7f);
float zz = Random.Range(-16f, -10f);
Instantiate(enemy[f], new Vector3(xx, 0.3f, zz), Quaternion.Euler(0, 180, 0));
}
yield return new WaitForSeconds(3f);// After cloning 3 second
}
}
}
Just send these first ;!!!!!!!
版权声明
本文为[C # primary advanced]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621093505.html
边栏推荐
- Knowledge of software testing~
- Five tips for cross-border e-commerce in 2022
- Build websocket server in. Net5 webapi
- MySQL installation pit
- 【VS Code】解决jupyter文件在vs code中显示异常的问题
- QT dynamic translation of Chinese and English languages
- 2022年做跨境电商五大技巧小分享
- Mysql database
- Batch download of files ---- compressed and then downloaded
- String input problem
猜你喜欢
IDEA查看历史记录【文件历史和项目历史】
Course design of Database Principle -- material distribution management system
General testing technology [1] classification of testing
Experiment 6 input / output stream
一套组合拳,打造一款 IDEA 护眼方案
Optimization of especially slow startup in idea debugging mode
[Mysql] LEFT函數 | RIGHT函數
Quartz. Www. 18fu Used in net core
Huawei mobile ADB devices connection device is empty
一文了解全面静态代码分析
随机推荐
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
. net core current limiting control - aspnetcoreratelimit
Problem C: realize Joseph Ring with linked list
[MySQL] left Function | Right Function
Quartz. Www. 18fu Used in net core
Visual programming -- how to customize the mouse cursor
"Visual programming" test paper
[untitled]
Supersocket is Used in net5 - command
Preview of converting doc and PDF to SWF file
ThreadLocal test multithreaded variable instance
2022t elevator repair test simulation 100 questions and online simulation test
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
Super easy to use [general excel import function]
poi根据数据创建导出excel
A set of combination boxing to create an idea eye protection scheme
一套组合拳,打造一款 IDEA 护眼方案
MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
New ORM framework -- Introduction to beetlsql
Top ten project management software similar to JIRA