1.什么是游戏引擎,请通过查阅资料详细说明。
游戏引擎是指一些已编写好的可编辑电脑游戏系统或者一些交互式实时图像应用程序的核心组件。这些系统为游戏设计者提供各种编写游戏所需的各种工具,其目的在于让游戏设计者能容易和快速地做出游戏程式而不用由零开始。

2.Unity中常用的组件有哪些?举五个以上例子,并阐述刚体组件的作用。

(1)Transform组件:控制游戏对象的位置、旋转和缩放

Position : 位置

Rotation : 旋转

Scale : 缩放

unity 引擎逻辑图_实例化


(2)Mesh Filter 组件:网状过滤器,可以更改其形态(立方体、球体等)

unity 引擎逻辑图_c#_02

(3)Box Collider 组件:盒型碰撞器,可以让游戏对象能实现碰撞的效果,用于做碰撞检测

unity 引擎逻辑图_unity 引擎逻辑图_03

(4)Mesh Renderer 组件:网格渲染器,保证在场景中看到个体、呈现渲染效果、给物体添加材质纹理等。

unity 引擎逻辑图_visual studio code_04

(5)Rigidbidy组件:刚体属性器,可以拥有质量、阻力、重力等物理属性。

unity 引擎逻辑图_c#_05

常用的还有以下:

unity 引擎逻辑图_实例化_06

3.如何通过代码方式创建一个游戏对象,并给它上色,以及改变它的坐标位置?

首先创建一个C# Script

创建一个原始游戏对象:GameObject obj=GameObject.CreatePrimitive(PrimitiveType.Capsule);

上色:obj.GetComponent<Renderer>().material.color=Color.cyan;

坐标位置:obj.transform.position=new Vector3(0.0f,2.0f,0.0f);

4.如何创建Prefab,并阐述其作用。

prefab:预制体,预设

作用:可以重复产生,可以重复利用

创建Prefab:先将小球(或其它)拖到下方设为预制体,然后创建一个空,接着代码Instantiate(this.ballPrefab);  实例化后,将小球拖给ballPrefab,即可使用预制

unity 引擎逻辑图_System_07


5.物体发生碰撞的必要条件是什么?

两个碰撞体边缘是否接触

上课代码:

1、创建游戏对象,上色,改变位置,加刚体组件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

	// Use this for initialization
	void Start () {

		GameObject obj=GameObject.CreatePrimitive(PrimitiveType.Capsule);
		obj.GetComponent<Renderer>().material.color=Color.cyan;
		obj.transform.position=new Vector3(0.0f,2.0f,0.0f);
		obj.AddComponent<Rigidbody> ();
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

2、点击鼠标左键弹跳

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class jump : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButtonDown(0)){
			this.GetComponent<Transform>().position+=new Vector3(3.0f,2.5f,5.0f);
		}
	}
}

3、刚开始就跳

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class all : MonoBehaviour {

	// Use this for initialization
	void Start () {
		this.GetComponent<Rigidbody>().velocity=new Vector3(-5.0f,5.0f,0.0f);   //开始就抛物线跳
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

4、点击鼠标右键发射,预制体的方式,不断点击不断发射

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class launch : MonoBehaviour {

	// Use this for initialization
	public GameObject ballPrefab;
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButtonDown(1)){
		Instantiate(this.ballPrefab);     //实例化	
		}
		
	}
	void OnBecameInvisible(){  //当游戏对象不在画面,销毁对象
         Destroy(this.gameObject);
	}
}