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:标准兼容 ...
随机推荐
- MDK(KEIL5)如何生成.bin文件 【转】
最近要做个bin文件,网上找了好多都说的不够清楚,后来找到一篇实测可用,说明清楚的,转过来以便学习用. 参考传送门:https://blog.csdn.net/nx505j/article/detai ...
- hdu 1598 暴力+并查集
#include<stdio.h> #include<stdlib.h> #define N 300 int pre[N]; int find(int u) { if(u!=p ...
- ACDream - Crayon
题目: Description There are only one case in each input file, the first line is a integer N (N ≤ 1,000 ...
- 介绍一个不错的服务器综合监控工具脚本集aspersa
http://blog.csdn.net/jackyrongvip/article/details/9217869
- mongodb--reduce并行处理框架
reduce 命令 db.runCommand( { mapReduce: <collection>, map: <function>, reduce: <functio ...
- POJ 2007
直接求凸包,输出即可. #include <iostream> #include <cstdio> #include <cstring> #include < ...
- 使用makeself创建安装文件
Makeself.sh是一个小的Shell脚本.用于从一个文件夹中生成自解压的tar.gz压缩包. 结果文件以一个shell脚本显示(大多数以.run作为后缀名).能够自己主动执行.该文档会解压自己到 ...
- cefsharp 获取高度
G.browser.GetBrowser().MainFrame.ExecuteJavaScriptAsync("$(document).height()"); // Get Do ...
- scanf,printf函数细节
今天笔试的时候遇到一个考察C语言scanf函数的题目 int x; float y; scanf("%3d%f",&x,&y); // input 123456 6 ...
- Hadoop Web项目--Friend Find系统
项目使用软件:Myeclipse10.0,JDK1.7,Hadoop2.6,MySQL5.6.EasyUI1.3.6.jQuery2.0,Spring4.1.3. Hibernate4.3.1,str ...