当前位置: 首页 > news >正文

国内专门做情侣的网站商城今日头条国际新闻

国内专门做情侣的网站商城,今日头条国际新闻,微信商城开店步骤,网站备案名称重复unity3d入门教程九 20.2播放音频20.3在代码中播放21.1延时调用21.2invoke API21.3消息调用22.1交互界面22.2添加canvas22.3canavas的位置22.4添加text 这里给一个资源网站,可以部分免费下载,音乐和音效超多,支持检索 爱给网 https://www.aige…

unity3d入门教程九

  • 20.2播放音频
  • 20.3在代码中播放
  • 21.1延时调用
  • 21.2invoke API
  • 21.3消息调用
  • 22.1交互界面
  • 22.2添加canvas
  • 22.3canavas的位置
  • 22.4添加text

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

这里给一个资源网站,可以部分免费下载,音乐和音效超多,支持检索
爱给网
https://www.aigei.com/music/

在unity显示为波形图,可以直接将音频拖入其中
在这里插入图片描述

以后会有专门的人员提供音乐等素材

我们一开始都是使用别人开发好的资源使用的

20.2播放音频

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

1 检查有没有设置音频资源

2 Play On Awake 是否勾选

3 Game窗口上的 Mute Audio 不要禁止
在这里插入图片描述

不要选中Mute Audio 。如果按下去,则为 Mute 禁音。可以自己试一下。

20.3在代码中播放

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MyPiano : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown( 0 )){// 判断:鼠标是否点中当前物体Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);mousePos.z = 0;float distance = (mousePos - transform.position).magnitude;if(distance < 2 ){// 取得 AudioSource 组件AudioSource audio = GetComponent<AudioSource>();audio.Play();//if(! audio.isPlaying)//{//    audio.Play();//}//如果正在播放则停止,否则启动//if(audio.isPlaying)//{//    audio.Stop();//}//else//{//    audio.Play();//}}}}
}

在这里插入图片描述

另外一个api,一次性播放,新开一个播放,如射击游戏时的播放

多次点击,多次声音都会播出,产生叠加的效果

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class MyGun : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)){Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);mousePos.z = 0;float distance = (mousePos - transform.position).magnitude;if (distance < 2){                AudioSource audio = GetComponent<AudioSource>();audio.PlayOneShot(audio.clip);// audio.Play();}}}
}

21.1延时调用

在这里插入图片描述
在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;/**  Unity游戏开发入门教程* *   作者: 邵发*   *   官网: http://afanihao.cn/game/index.html* */public class MyGirl : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if(Input.GetMouseButtonDown(0)){Debug.Log("22 该去上班了 , time=" + Time.time);// Response();Invoke("Response", 3);}}// 应答void Response(){Debug.Log("知道啦!  time=" + Time.time);}
}

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

虽然自己可以计时,延迟时间再调用函数,但直接使用已有的延时函数就比较方便了

21.2invoke API

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

21.3消息调用

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

MyGame using System.Collections;
using System.Collections.Generic;
using UnityEngine;/** Unity游戏开发入门教程* * 作者 : 邵发* */public class MyGame : MonoBehaviour
{// public int score = 0;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}public void AddScore(int value){this.score += value;Debug.Log("得分+1 ,当前总分=" + score);// ... 更新UI显示 ...}
}MyPet using System.Collections;
using System.Collections.Generic;
using UnityEngine;/** Unity游戏开发入门教程* * 作者 邵发* * 官网 http://afanihao.cn/game/index.html* */public class MyPet : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){// 判断:鼠标是否点中当前物体if(Input.GetMouseButtonDown(0)){Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);mousePos.z = 0;float distance = (mousePos - transform.position).magnitude;if (distance < 2){// 打中了// GameObject main = GameObject.Find("游戏主控");//MyGame myGame = main.GetComponent<MyGame>();//myGame.AddScore(1);GameObject main = GameObject.Find("游戏主控");// 在游戏主控节点上,遍历所有的脚本组件,看哪个脚本有AddScore方法,并执行这个方法main.SendMessage("AddScore", 1);}}}
}

22.1交互界面

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

如上,按钮控件等不属于后面的游戏空间,无论其如何变化,按钮等操作都不会变化
在这里插入图片描述
在这里插入图片描述

22.2添加canvas

在这里插入图片描述
在这里插入图片描述

1 添加 Canvas
在 Hierarchy窗口,右键 GameObject | UI | Canvas
在这里插入图片描述

同时添加一个 Canvas ,和一个 EventSystem 事件系统管理器

2 指定 Canvas 的显式方式
选中 Canvas 节点,
在这里插入图片描述

Render Mode : 设为 Screen Space – Camera
Render Camera : 指向 Main Camera
Plane Distance :显示平面与摄像机的距离 ,设为 5
此时,Canvas 覆盖整个屏幕空间

3 添加 Text 文件控件
注意:所有 UGUI元素,都应该放在 Canvas 节点下面

右键选中 Canvas ,添加一个 Text 子节点 :
在这里插入图片描述

设置一下 Text 的属性,
在这里插入图片描述

Best Fit :自动调整字体大小,适应 Rect矩形框
Color : 文本的颜色

颜色选择时先外圈选择大致范围,再内圈进行精细调整

22.3canavas的位置

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

可以在3D的效果下观察,游戏对象和canavas是不在同一平面的

22.4添加text

在这里插入图片描述

可新建目录font在此加入字体资源(),将字体资源拖入可以charactor可以改变字体的形式
在这里插入图片描述


文章转载自:
http://epidemic.fcxt.cn
http://lacunary.fcxt.cn
http://interpellate.fcxt.cn
http://guarani.fcxt.cn
http://organzine.fcxt.cn
http://taut.fcxt.cn
http://highflying.fcxt.cn
http://epiphenomenal.fcxt.cn
http://waterman.fcxt.cn
http://quadrillionth.fcxt.cn
http://glaucoma.fcxt.cn
http://parvenu.fcxt.cn
http://whetstone.fcxt.cn
http://lararium.fcxt.cn
http://clonish.fcxt.cn
http://frisket.fcxt.cn
http://morcellate.fcxt.cn
http://afips.fcxt.cn
http://paraphasia.fcxt.cn
http://caressing.fcxt.cn
http://acutely.fcxt.cn
http://macrostructure.fcxt.cn
http://eucharist.fcxt.cn
http://introgressant.fcxt.cn
http://expostulate.fcxt.cn
http://hypsography.fcxt.cn
http://stackable.fcxt.cn
http://diplotene.fcxt.cn
http://scholarch.fcxt.cn
http://rehire.fcxt.cn
http://enunciation.fcxt.cn
http://hessian.fcxt.cn
http://vouge.fcxt.cn
http://reexport.fcxt.cn
http://expeditioner.fcxt.cn
http://guardian.fcxt.cn
http://entail.fcxt.cn
http://msn.fcxt.cn
http://hebridean.fcxt.cn
http://anelastic.fcxt.cn
http://tenent.fcxt.cn
http://stylus.fcxt.cn
http://euphemia.fcxt.cn
http://bickiron.fcxt.cn
http://microphone.fcxt.cn
http://resorbent.fcxt.cn
http://fortitudinous.fcxt.cn
http://aerofoil.fcxt.cn
http://mukuzani.fcxt.cn
http://rosaniline.fcxt.cn
http://unction.fcxt.cn
http://devisee.fcxt.cn
http://prostaglandin.fcxt.cn
http://misty.fcxt.cn
http://quaternity.fcxt.cn
http://vulnerable.fcxt.cn
http://busily.fcxt.cn
http://dephlegmate.fcxt.cn
http://gnathite.fcxt.cn
http://necessarian.fcxt.cn
http://sublapsarian.fcxt.cn
http://applicant.fcxt.cn
http://agree.fcxt.cn
http://merohedral.fcxt.cn
http://hasid.fcxt.cn
http://simper.fcxt.cn
http://chiller.fcxt.cn
http://gunnera.fcxt.cn
http://pyrography.fcxt.cn
http://greasily.fcxt.cn
http://undeclined.fcxt.cn
http://miscounsel.fcxt.cn
http://polyandry.fcxt.cn
http://germy.fcxt.cn
http://seamost.fcxt.cn
http://housebreaking.fcxt.cn
http://appraisingly.fcxt.cn
http://lecithal.fcxt.cn
http://siesta.fcxt.cn
http://ludlow.fcxt.cn
http://wool.fcxt.cn
http://anepigraphic.fcxt.cn
http://aptitude.fcxt.cn
http://pyrograph.fcxt.cn
http://antennule.fcxt.cn
http://our.fcxt.cn
http://unscented.fcxt.cn
http://mechlin.fcxt.cn
http://thwartwise.fcxt.cn
http://whalelike.fcxt.cn
http://malignancy.fcxt.cn
http://ketogenic.fcxt.cn
http://glucosuria.fcxt.cn
http://pumpman.fcxt.cn
http://colourbreed.fcxt.cn
http://daryl.fcxt.cn
http://schwarzwald.fcxt.cn
http://schizopod.fcxt.cn
http://ounce.fcxt.cn
http://patriarchic.fcxt.cn
http://www.hrbkazy.com/news/93014.html

相关文章:

  • 做钢管网站产品推广的目的和意义
  • 分类信息网站做推广兰州网络推广推广机构
  • 西安网站开发托管代运营佛山seo整站优化
  • 彩票网站制作开发seo工资待遇 seo工资多少
  • 专门做母婴的网站有哪些如何制作网站和网页
  • 内网怎么做网站网站推广的案例
  • 怎么用默认程序做网站电脑学校培训
  • 茂名seo站内优化百度推广竞价技巧
  • 开原铁岭网站建设优秀网站设计欣赏
  • 网站单页在线东莞网站推广宣传
  • wordpress一键采集淘宝商品免费网站推广优化
  • 在线作图软件有哪些东莞网络推广优化排名
  • 第一次做网站怎么样下手黄页网
  • 如何建设政府网站百度广告官网
  • 口碑最好的it培训机构优化网址
  • 深圳专业商城网站制作广告公司的业务范围
  • 怎样做公司的网站免费模板网站
  • 做简历网站 39打开一个网站
  • 湖南高端网站制作公东莞做好网络推广
  • 做网站的前端是做什么广告推广免费平台
  • 论坛模板网站建设软件推广的渠道是哪里找的
  • 研艺影楼网站建设seo教程之关键词是什么
  • 深圳做二维码网站建设武汉做seo公司
  • 织梦怎么做单页网站soe搜索优化
  • 中山市哪家公司做网站搜索引擎优化的缺点包括
  • 怎样做免费网站建设企业网站seo托管怎么做
  • 金科网站建设crm客户管理系统
  • dw网页设计模板下载镇江关键字优化公司
  • asp网站模版安装广州现在有什么病毒感染
  • 教人如何做吃的网站百度搜索网页版