Unity3D-Homework3

这篇博客介绍了Unity3D的编程作业,包括实现物体的抛物线运动和创建太阳系模拟。作业中详细讲述了如何通过改变Transform属性、使用translate方法以及Vector3实现物体抛物线运动。此外,还解析了一款名为'Priests and Devils'的游戏,列出了游戏元素、玩家动作表,并讨论了游戏对象的预制、集合类型组织、MVC架构以及代码实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作业内容

1、简答并用程序验证【建议做】
  • 游戏对象运动的本质是什么?
    游戏对象运动的本质是:游戏对象在游戏每一帧的渲染过程中Transform属性在发生变化。这里物体的Transform属性是指Position与Rotation两个属性。
  • 请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
    第一种方法,直接通过改变物体的Transform的position属性让物体实现抛物线运动。代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class parabola : MonoBehaviour {
   
   
    public float speed1 = 4;
    public float speed2 = 0;
    public float speed = 3;
	// Use this for initialization
	void Start () {
   
   
        Debug.Log("Init start");
	}
	
	// Update is called once per frame
	void Update () {
   
   
        if(speed1 >= 0){
   
   
            speed1 = speed1 - 10 * Time.deltaTime;
            this.transform.position += Vector3.up * Time.deltaTime * speed1 / 2;
        }
        else{
   
   
            speed2 = speed2 + 10 * Time.deltaTime;
            this.transform.position += Vector3.down * Time.deltaTime * speed2 / 2;
        }
        this.transform.position += Vector3.left * Time.deltaTime * speed;
	}
}

第二种方法,使用transform中的translate方法改变对象的位置。代码如下:

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

public class parabola : MonoBehaviour {
   
   
    public float speed1 = 4;
    public float speed2 = 0;
    public float speed = 3;
	// Use this for initialization
	void Start () {
   
   
        Debug.Log("Init start");
	}
	
	// Update is called once per frame
	void Update () {
   
   
        if(speed1 >= 0)
        {
   
   
            speed1 = speed1 - 10 * Time.deltaTime;
            transform.Translate(Vector3.up * Time.deltaTime * speed1 / 2, Space.World);
        }
        else
        {
   
   
            speed2 = speed2 + 10 * Time.deltaTime;
            transform.Translate(Vector3.down * Time.deltaTime * speed2 / 2, Space.World);
        }
        transform.Translate(Vector3.left * Time.deltaTime * speed);
	}
}

第三种方法,新建一个vector3对象,改变这个对象的值,然后直接赋给物体。代码如下:

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

public class parabola : MonoBehaviour {
   
   
    public float speed1 = 4;
    public float speed2 = 0;
    public float speed = 3;
	// Use this for initialization
	void Start () {
   
   
        Debug.Log("Init start");
	}
	
	// Update is called once per frame
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值