获取对象的位置(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_脚本_获取对象的位置_碰撞后加一段音乐_旋转对象_使物体随机运动的更多相关文章

  1. 13_Java面向对象_第13天(static、final、匿名对象、内部类、包、修饰符、代码块)_讲义

    今日内容介绍 1.final 关键字 2.static 关键字 3.匿名对象 4.内部类 5.包的声明与访问 6.访问修饰符 7.代码块 01final关键字概念 A: 概述 继承的出现提高了代码的复 ...

  2. Python获取当前时间_获取格式化时间_格式化日期

    Python获取当前时间_获取格式化时间: Python获取当前时间: 使用 time.time( ) 获取到距离1970年1月1日的秒数(浮点数),然后传递给 localtime 获取当前时间 #使 ...

  3. [C++]_[获取Utf8字符串的字符个数和子字符串]

    场景: 1.有时候须要统计utf8字符串的个数,单纯统计字节个数是不行的. 2.有时候也须要获取从某个位置開始的n个连续字符用于显示或计算. static int GetUtf8LetterNumbe ...

  4. 使用 shell 脚本自动获取发版指标数据

    问题背景 大一点的公司都会建立一套规章流程来避免低级错误,例如合入代码前必需经过同行评审:上线前必需提测且通过 QA 验证:全量前必需经过 1%.5%.10%.20%.50% 的灰度过程.尤其是最后一 ...

  5. 获取DOM元素位置和尺寸大小

    JavaScript获取DOM元素位置和尺寸大小 在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽 ...

  6. js获取控件位置以及不同浏览器中的差别

    js获取控件位置(坐标位置)在不同浏览器中的差别. //获取坐标位置 function getpos(e) { var t=e.offsetTop; var l=e.offsetLeft; var h ...

  7. java:javaScript(定义方式,循环语句,函数与参数,事件机制,控制台记录,event事件获取键盘ascii,confirm和prompt,事件和内置对象,获取input,点击更换背景色)

    1. 定义JS的两种方式: <!DOCTYPE> <html> <head> <meta charset="UTF-8"></ ...

  8. ionic 获取手机所在位置

    之前项目中需要使用到定位功能,前边的文章提到的坐标位置是有问题的,是国际坐标,国内的环境使用google地图会出现问题,所以需要使用国内的地图进行坐标解析,因为国内和国外的坐标体系不一致,需要通过转换 ...

  9. document.compatMode属性和获取鼠标的位置

    document.compatMode属性 document.compatMode用来判断当前浏览器采用的渲染方式. 官方解释: BackCompat:标准兼容模式关闭.CSS1Compat:标准兼容 ...

随机推荐

  1. 重命名文件及html

    import os import nltk from bs4 import BeautifulSoup as bs def get_txt_name_from_bak_name(bak_name): ...

  2. LID&LDS 的另外一种算法

    参见:LIS,LDS的另类算法(原) 然后讲讲我的想法:  有结论不上升子序列的个数=最长上升子序列的长度.....至于为什么,在下面讲 上代码: #include <iostream> ...

  3. foj 2139

    hi.baidu.com/ydlqw/item/120cd21a5afd5becddeeca41?qq-pf-to=pcqq.c2c

  4. Codeforces444A_DZY Loves Physics

    DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. HDU 5412 CRB and Queries(区间第K大 树套树 按值建树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5412 Problem Description There are N boys in CodeLan ...

  6. HDOJ1796 How many integers can you find(dfs+容斥)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. PL SQL Developer client 连接server

    安装完Oracle,PLSQL之后,在server中打开监听. 计算机右键-管理-服务和应用程序-服务-打开以Oracle开头的服务,特别是监听,这个最重要.详细如图所看到的. (1)配置监听的位置 ...

  8. python spark 通过key来统计不同values个数

    >>> rdd = sc.parallelize([("), ("b", 1), ("a", 1), ("a", ...

  9. 2014.9.20Hashtable概述

    hashtable叫哈希表,用于表示键值的集合,这些键值对根据键的哈希代码进行组织,其每个元素都存储于DictionaryEntry对象中的键值对.键不能为空引用. count:获取包含在hashta ...

  10. ASP.NET Core Web API下事件驱动型架构的实现

    mvp 原创博文:http://www.cnblogs.com/daxnet/p/8082694.html