Unity3D学习笔记(二):个体层次、绝对和局部坐标、V3平移旋转
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175417605-2105466491.png)
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175424926-2058330089.png)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyLight : MonoBehaviour
{
// Use this for initialization
void Start()
{
Light light = GetComponent<Light>();
light.intensity = ;
//int[] array = new int[] { 1, 2, 3, 4, 5, 6 };
if (light != null)
{
Debug.Log(light.intensity);
}
}
// Update is called once per frame
void Update()
{
}
}
![](https://img2018.cnblogs.com/blog/1517599/201903/1517599-20190326214138174-1609264624.png)
对于单个物体可以在Mesh Renderer中的Cast Shadows选择是否产生阴影,Receive Shadows中选择是否接受阴影;
对于整个地图可以在光源的inspector面板打开和关闭。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Find_Parent : MonoBehaviour
{
public GameObject sphere;
// Use this for initialization
void Start()
{
//如何在整个场景中查找游戏物体
//查找写成静态方法,是工具,不是某一个对象的方法
sphere = GameObject.Find("Find_Parent/Sphere");
Debug.Log(sphere.name);
//建立父子关系,需要关联transform
gameObject.transform.parent = sphere.transform;
}
// Update is called once per frame
void Update()
{
//不要在Update进行查找,GameObject.Find("Sphere");
//要建一个全局的sphere初始化
//移动父物体,子物体也会动
if (sphere)
{
sphere.transform.Translate(new Vector3(, , 0.1f));
// //或者
// sphere.transform.Translate(Vector3.forward * 0.1f);
}
}
}
Unity找到父物体下的子物体
GameObject obj = GameObject.Find("Image Bg");
//首先找到父物体
GameObject zhen = obj.transform.Find("zhen").gameObject;
//然后找到父物体下的子物体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetComponent : MonoBehaviour {
// Use this for initialization
void Start () {
Transform trans = GetComponent<Transform>();
//GetComponent获取组件的方法,加()表执行
//GetComponent获取不到组件,会返回空引用变量(空指针),在使用的时候,会报空引用异常的错误
Transform trans = null;
Debug.Log(trans.position);
if (trans != null)
{
Debug.Log(trans.position);
}
//transform
transform.position = new Vector3(, , );//不能只修改transform.position某个分量的值,需要对transform.position整体重新赋值,才会有返回值
Debug.Log(transform.position);
}
// Update is called once per frame
void Update () { }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddComponent : MonoBehaviour {
// Use this for initialization
void Start () {
Light light = gameObject.AddComponent<Light>();
light.intensity = ;
light.type = LightType.Spot;
light.color = Color.green;
Destroy(light, 5.0f);
}
// Update is called once per frame
void Update () { }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Destroy : MonoBehaviour {
// Use this for initialization
void Start () {
AudioSource audio = GetComponent<AudioSource>();
if (audio)//audio是传进来的引用
{
Destroy(audio);
//5秒后销毁audio引用
Destroy(audio, );
//5秒后销毁Lesson3脚本组件
Destroy(this, );
}
}
// Update is called once per frame
void Update () { }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public float moveSpeed = 0.5f;
// Use this for initialization
void Start()
{
// transform.position = new Vector3(3.0f, 3.0f, 3.0f);//不要放在循环里用,调用一次就够了
}
// Update is called once per frame
void Update()
{
if (transform.position.z < 10.0f)
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
else
{
transform.position = new Vector3(3.0f, 3.0f, 3.0f);
}
//每帧z轴都移动0.1f,当前坐标加上新坐标,再返回给原坐标
transform.position += new Vector3(, , 0.1f);
//Translate平移
transform.Translate(new Vector3(, , 0.1f));
//自定义myTranslate
myTranslate(new Vector3(, , 0.1f));
}
void myTranslate(Vector3 translation)
{
transform.position += new Vector3(, , 0.1f);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveControl : MonoBehaviour
{
private float moveSpeed = ;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
this.transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.S))
{
this.transform.Translate(Vector3.back * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.A))
{
this.transform.Translate(Vector3.left * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.D))
{
this.transform.Translate(Vector3.right * Time.deltaTime * moveSpeed);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class position_eulerAngles : MonoBehaviour {
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
transform.position += Vector3.back * 0.05f;
transform.eulerAngles += Vector3.up;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//旋转
//欧拉角
transform.eulerAngles += new Vector3(, , 0.1f);
transform.eulerAngles += Vector3.up;
//旋转的API是Rotate
transform.Rotate(Vector3.up);
}
}
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175836739-879183621.png)
Behaviour继承于Component,Component是所有组件的基类,enabled:组件是否激活
Object是Component的基类,组件的本质是Object类
GetComponent获取不到组件,会返回空引用变量(空指针),在使用的时候,会报空引用异常的错误
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175934336-177052841.png)
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175947820-1453758832.png)
![](https://img2018.cnblogs.com/blog/1517599/201902/1517599-20190211175956012-467092321.png)
点光源,立方体贴图(六个面可以不一样),cookie
Halo光晕
Layer:给游戏物体添加层
Culing Mask遮罩剔除:光源对那些层(游戏物体)起作用
子物体从父物体拖出,会叠加上父物体的Transform,Position和Rotation做加法,Scale做乘法
F12进入定义,a是alpha通道
拖拽游戏物体到脚本组件,可以自动赋值
Unity3D学习笔记(二):个体层次、绝对和局部坐标、V3平移旋转的更多相关文章
- 【Qt官方例程学习笔记】Analog Clock Window Example (画笔的平移/旋转/缩放应用)
这个例子演示了如何使用QPainter的转换和缩放特性来简化绘图. 值得学习的: 定时器事件ID检查: 在定时器事件中检查定时器id是比较好的实践. QPainter抗锯齿: We call QPai ...
- 学习笔记(二)--->《Java 8编程官方参考教程(第9版).pdf》:第七章到九章学习笔记
注:本文声明事项. 本博文整理者:刘军 本博文出自于: <Java8 编程官方参考教程>一书 声明:1:转载请标注出处.本文不得作为商业活动.若有违本之,则本人不负法律责任.违法者自负一切 ...
- amazeui学习笔记二(进阶开发4)--JavaScript规范Rules
amazeui学习笔记二(进阶开发4)--JavaScript规范Rules 一.总结 1.注释规范总原则: As short as possible(如无必要,勿增注释):尽量提高代码本身的清晰性. ...
- Unity3D学习笔记12——渲染纹理
目录 1. 概述 2. 详论 3. 问题 1. 概述 在文章<Unity3D学习笔记11--后处理>中论述了后处理是帧缓存(Framebuffer)技术实现之一:而另外一个帧缓存技术实现就 ...
- WPF的Binding学习笔记(二)
原文: http://www.cnblogs.com/pasoraku/archive/2012/10/25/2738428.htmlWPF的Binding学习笔记(二) 上次学了点点Binding的 ...
- AJax 学习笔记二(onreadystatechange的作用)
AJax 学习笔记二(onreadystatechange的作用) 当发送一个请求后,客户端无法确定什么时候会完成这个请求,所以需要用事件机制来捕获请求的状态XMLHttpRequest对象提供了on ...
- [Firefly引擎][学习笔记二][已完结]卡牌游戏开发模型的设计
源地址:http://bbs.9miao.com/thread-44603-1-1.html 在此补充一下Socket的验证机制:socket登陆验证.会采用session会话超时的机制做心跳接口验证 ...
- JMX学习笔记(二)-Notification
Notification通知,也可理解为消息,有通知,必然有发送通知的广播,JMX这里采用了一种订阅的方式,类似于观察者模式,注册一个观察者到广播里,当有通知时,广播通过调用观察者,逐一通知. 这里写 ...
- java之jvm学习笔记二(类装载器的体系结构)
java的class只在需要的时候才内转载入内存,并由java虚拟机的执行引擎来执行,而执行引擎从总的来说主要的执行方式分为四种, 第一种,一次性解释代码,也就是当字节码转载到内存后,每次需要都会重新 ...
- Java IO学习笔记二
Java IO学习笔记二 流的概念 在程序中所有的数据都是以流的方式进行传输或保存的,程序需要数据的时候要使用输入流读取数据,而当程序需要将一些数据保存起来的时候,就要使用输出流完成. 程序中的输入输 ...
随机推荐
- mysql 数据操作 多表查询 目录
mysql 数据操作 多表查询 准备 多表连接查询介绍 mysql 数据操作 多表查询 多表连接查询 笛卡尔积 mysql 数据操作 多表查询 多表连接查询 内连接 mysql 数据操作 多表查询 多 ...
- 使用navicat mysql 远程连接数据库
远程连接数据库,假设两台主机上都有navicat 客户端 远程主机A ip地址:192.168.100.91 ,port 3306,数据库用户名 rootA 密码 123456A 本地主 ...
- POJ3096:Surprising Strings(map)
http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...
- loadrunner 接口性能脚本编写(Get请求和Post请求)
前段时间接触了一下loadrunner的接口性能测试,然后尝试了一下手动编写脚本,毕竟录制这种东西,不是每次都能通的,而且录制下来的脚本,通常是有很多其他杂七杂八的请求夹杂在中间,没有达到真正的压测接 ...
- Python线程,进程,携程,I/O同步,异步
只有本人能看懂的-Python线程,进程,携程,I/O同步,异步 举个栗子: 我想get三个url,先用普通的for循环 import requests from multiprocessing im ...
- Problem B. Full Binary Tree
题目 链接:http://code.google.com/codejam/contest/2984486/dashboard#s=p1 googlde code jam 2014 Round1A 解题 ...
- Linux系统——PXE高效能批量网络装机
PXE:Pre-boot Excution Environment,预启动执行环境,石油Intel公司开发的网络引导技术,工作在Client.Server模式,允许客户机通过网络从远程服务器下载阴道镜 ...
- 自动加载 autoload
自动加载 是什么时候调用的 是实例化某个对象的时候,在当前脚本中没有找到对应类的时候 ,如果当前找到了就不会调用__autoload方法 例如:例子一,找到类 <?php function _ ...
- n是否是2的幂
实例五:n是否是2的幂 方法一:result=n&(n-1) 如果result=0 则n是2的幂方法二:result=n&((~n)+1) 如果result=n 则n是2的幂 原数 ...
- C++ 简明教程
C++是一种系统编程语言.用它的发明者, Bjarne Stroustrup的话来说,C++的设计目标是: 成为“更好的C语言” 支持数据的抽象与封装 支持面向对象编程 支持泛型编程 C++提供了对硬 ...