Unity3D学习笔记(二):个体层次、绝对和局部坐标、V3平移旋转


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()
{
}
}

对于单个物体可以在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);
}
}

Behaviour继承于Component,Component是所有组件的基类,enabled:组件是否激活
Object是Component的基类,组件的本质是Object类
GetComponent获取不到组件,会返回空引用变量(空指针),在使用的时候,会报空引用异常的错误



点光源,立方体贴图(六个面可以不一样),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学习笔记二 流的概念 在程序中所有的数据都是以流的方式进行传输或保存的,程序需要数据的时候要使用输入流读取数据,而当程序需要将一些数据保存起来的时候,就要使用输出流完成. 程序中的输入输 ...
随机推荐
- 改变wordpress图片上传后的压缩质量
WordPress 在图片上传后会默认压缩图片质量为原来的 90%,这样做的好处可以极大的加快页面的载入速度与缩小图片大小所占服务器空间. 如果希望 100% 原质量怎么办呢?如何禁止 WordPre ...
- Tomcat修改端口和编码配置
1.打开Tomcat中server.xml文件,找到原本的8080,修改成没被占用的端口: 2.在这个标签里增加 URIEncoding="utf-8",修改请求的编码.
- 批量生成反色图片,用PHOTOSHOP批处理功能。
http://zhidao.baidu.com/link?url=Iz46PDPnEITummTEwo2GtUrK6AeAjlidJ7HtCPJ6NYZJbbllRwNg2iBAcNwF2TYjccP ...
- python ddt 实现数据驱动一
ddt 是第三方模块,需安装, pip install ddt DDT包含类的装饰器ddt和两个方法装饰器data(直接输入测试数据) 通常情况下,data中的数据按照一个参数传递给测试用例,如果da ...
- Java接口多线程并发测试 (二)
原文地址http://www.cnblogs.com/yezhenhan/archive/2012/01/09/2317636.html 这是一篇很不错的文章,感谢原博主的分享! JAVA多线程实现和 ...
- 把 ElasticSearch 当成是 NoSQL 数据库
Elasticsearch 可以被当成一个 “NoSQL”-数据库来使用么? NoSQL 意味着在不同的环境下存在不同的东西, 而erestingly 它并不是真的跟 SQL 有啥关系. 我们开始只会 ...
- Codeforces Round #246 (Div. 2) D E
这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用KMP解 用0开头的那种类型的 KMP 今天刚好也学了一下,因为KMP的作用是找出最长前缀 KMP ...
- MySQL从删库到跑路_高级(四)——存储过程
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.存储过程简介 1.存储过程简介 存储过程是一组具有特定功能的SQl语句集组成的可编程的函数,经编译创建并保存在数 ...
- MySQL从删库到跑路_高级(三)——视图
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.视图简介 1.视图简介 视图是由SELECT查询语句所定义的一个虚拟表,是查看数据的一种非常有效的方式.视图包含 ...
- REST服务安全-双向认证
1. 创建服务器密钥,其密钥库为 d:/mykeys/server.ks,注意keypass和storepass保持一致,它们分别代表 密钥密码和密钥库密码,注意 CN=localhost 中,loc ...