Unity3D_脚本_获取对象的位置_碰撞后加一段音乐_旋转对象_使物体随机运动
获取对象的位置(Position)
在代码中加上
public Rigidbody cd;
cd = GetComponent<Rigidbody>();
Vector3 m=cd.transform.position;
1
2
3
m[0]为y轴世界坐标
m[1]为y轴世界坐标
m[2]为y轴世界坐标
碰撞后加一段音乐
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sound : MonoBehaviour
{
//播放音乐
public AudioClip[] bg_sounds;
private AudioSource audio_source;
void Awake ()
{
audio_source = GetComponent<AudioSource> ();
audio_source.volume = 1;
audio_source.clip = bg_sounds [0];
audio_source.Play();
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnter(Collision collison)
{
audio_source.clip = bg_sounds[1];
audio_source.Play();
Application.LoadLevel("endGame");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
旋转对象
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotator : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
使物体随机运动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rend : MonoBehaviour {
public float speed;
private float moveSpeed=4;//移动速度.
void Start () {
//设置初始位置.
transform.position=new Vector3(5,0,0);
}
// Update is called once per frame
void Update () {
if(transform.position.x>-22){
//移动.
transform.Translate(Vector3.right*-moveSpeed*Time.deltaTime);
}
else{
transform.position=new Vector3(5,0,0);
}
}
}
---------------------
Unity3D_脚本_获取对象的位置_碰撞后加一段音乐_旋转对象_使物体随机运动的更多相关文章
- 13_Java面向对象_第13天(static、final、匿名对象、内部类、包、修饰符、代码块)_讲义
今日内容介绍 1.final 关键字 2.static 关键字 3.匿名对象 4.内部类 5.包的声明与访问 6.访问修饰符 7.代码块 01final关键字概念 A: 概述 继承的出现提高了代码的复 ...
- Python获取当前时间_获取格式化时间_格式化日期
Python获取当前时间_获取格式化时间: Python获取当前时间: 使用 time.time( ) 获取到距离1970年1月1日的秒数(浮点数),然后传递给 localtime 获取当前时间 #使 ...
- [C++]_[获取Utf8字符串的字符个数和子字符串]
场景: 1.有时候须要统计utf8字符串的个数,单纯统计字节个数是不行的. 2.有时候也须要获取从某个位置開始的n个连续字符用于显示或计算. static int GetUtf8LetterNumbe ...
- 使用 shell 脚本自动获取发版指标数据
问题背景 大一点的公司都会建立一套规章流程来避免低级错误,例如合入代码前必需经过同行评审:上线前必需提测且通过 QA 验证:全量前必需经过 1%.5%.10%.20%.50% 的灰度过程.尤其是最后一 ...
- 获取DOM元素位置和尺寸大小
JavaScript获取DOM元素位置和尺寸大小 在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽 ...
- js获取控件位置以及不同浏览器中的差别
js获取控件位置(坐标位置)在不同浏览器中的差别. //获取坐标位置 function getpos(e) { var t=e.offsetTop; var l=e.offsetLeft; var h ...
- java:javaScript(定义方式,循环语句,函数与参数,事件机制,控制台记录,event事件获取键盘ascii,confirm和prompt,事件和内置对象,获取input,点击更换背景色)
1. 定义JS的两种方式: <!DOCTYPE> <html> <head> <meta charset="UTF-8"></ ...
- ionic 获取手机所在位置
之前项目中需要使用到定位功能,前边的文章提到的坐标位置是有问题的,是国际坐标,国内的环境使用google地图会出现问题,所以需要使用国内的地图进行坐标解析,因为国内和国外的坐标体系不一致,需要通过转换 ...
- document.compatMode属性和获取鼠标的位置
document.compatMode属性 document.compatMode用来判断当前浏览器采用的渲染方式. 官方解释: BackCompat:标准兼容模式关闭.CSS1Compat:标准兼容 ...
随机推荐
- Problem 20
Problem 20 问题网址:https://projecteuler.net/problem=20 n! means n × (n − 1) × ... × 3 × 2 × 1阶乘For exam ...
- 2019-04-18 Python Base 1
C:\Users\Jeffery1u>python Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64 ...
- Java设计模式之 — 单例(Singleton)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8860649 写软件的时候经常需要用到打印日志功能,可以帮助你调试和定位问题,项目上 ...
- wordpress常见问题
一.WordPress新手必须注意的两个设置 第一 :设置里面的媒体--关闭wordpress缩略图功能如果开启了三种缩略图,博客上传的图片就会生成不同大小的三份,而基本上博客又没有使用,这样下来严重 ...
- Spring Cloud-Bus(十二)
说明 用于分布式上所有微服务都连接到消息总线上面.进行统一的通知 Config动态刷新 configClient configClient通过/actuator/bus-refresh端点通知消息总线 ...
- C语言遍历文件和文件夹——————【Badboy】
[cpp] #include #include #include #include #include #include #include #define MAX_PATH_LENGTH 512 #de ...
- 黑马程序猿——JAVA基础——集合
----------android培训.java培训.java学习型技术博客.期待与您交流.------------ 一.关于java中的集合类 首先看一下,大致的框架流程图 ...
- Webx框架:Spring Schema 和 Spring Ext
webx诞生的原因是当时市面上没有好用的web框架.如今的Web框架有非常多.然后它们背后的思想都是相似的,并且越来越趋同. Spring Schema 在传统的spring中,配置bean时须要手动 ...
- UVA 4855 Hyper Box
You live in the universe X where all the physical laws and constants are different from ours. For ex ...
- luogu2431 正妹吃月饼
题目大意 求一个正整数集合\(K\),使得\(\sum_{k\in K}2^k\in[A,B]\),且\(|K|\)最大.\(A,B\)大小在long long范围内. 思路 \(\sum_{k\in ...