首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >实例化坐标C#

实例化坐标C#
EN

Stack Overflow用户
提问于 2013-06-13 10:01:14
回答 1查看 673关注 0票数 0

我正在做一个与RPC网络统一的游戏,我想在特定的坐标下产生玩家。这是新的玩家衍生代码:`

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[RPC]
void JoinPlayer(NetworkViewID newPlayerView, Vector3 pos, NetworkPlayer p)
{
    // instantiate the prefab
    // and set some of its properties

    GameObject newPlayer = Instantiate(playerPrefab, pos, Quaternion.identity) as GameObject;
    newPlayer.GetComponent<NetworkView>().viewID = newPlayerView;
    newPlayer.tag = "Player";

    // set the remote player's target to its current location
    // so that non-moving remote player don't move to the origin
    newPlayer.GetComponent<playerController>().target = pos;

    // most importantly, populate the NetworkPlayer
    // structure with the data received from the player
    // this will allow us to ignore updates from ourself

    newPlayer.GetComponent<playerController>().netPlayer = p;

    // the local GameObject for any player is unknown to
    // the server, so it can only send updates for NetworkPlayer
    // IDs - which we need to translate to a player's local
    // GameObject representation

    // to do this, we will add the player to the "players" Hashtable
    // for fast reverse-lookups for player updates
    // Hashtable structure is NetworkPlayer --> GameObject


    players.Add(p,newPlayer);
    `

那么我如何在特定的坐标下产生一个玩家呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-13 10:28:13

只需给出对象坐标即可。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
GameObject newPlayer = Instantiate(playerPrefab, 
                                   pos, 
                                   Quaternion.identity) as GameObject;

使用上面的代码,可以调用函数Instantiate()。此方法的参数为:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
static function Instantiate (original : Object, 
                             position : Vector3, 
                             rotation : Quaternion) : Object 

position参数就是它所说的:新创建的对象的位置。如果你想看一些例子,click here for the Script Reference

因此,例如,如果您有坐标505,7,369,您可以在实例化代码上添加以下代码行:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Vector3 pos = new Vector3(505, 7, 369);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17084266

复制
相关文章
C#中Serializable序列化实例
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
bering
2019/12/02
1.8K0
C#——获取鼠标当前坐标
this.PointToClient(Control.MousePosition): 将指定屏幕点的位置计算成工作区坐标 (鼠标相对于窗体工作区的坐标);
vv彭
2021/02/04
3.8K0
C#——获取鼠标当前坐标
C#反射与特性(四):实例化类型
前面三篇文章,介绍了使用程序集、获取 Type 类型、使用 Type 类型获取成员信息。
痴者工良
2021/04/26
1.2K0
C#构造方法--实例化类时初始化的方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { a a1 = new a(); Console.ReadKey();
杨奉武
2018/04/17
1.7K0
C#构造方法--实例化类时初始化的方法
C#反射实例
C#反射的入门学习首先要明白C#反射提供了封装程序集、模块和类型的对象等等。那么这样可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性。如果代码中使用了属性,可以利用反射对它们进行访问。 MSDN描述:
zls365
2021/03/16
1.1K0
C#反射实例
C# 封装实例
如下图,有很多方法都要重复利用一段代码,所以他需要把它封装成为一个方法去调用,但是 这个键盘按下事件 他不知道怎么封装.
zls365
2020/08/19
9830
C# 封装实例
chart控件获取鼠标点击坐标,十字坐标跟随——c#
private void chart1_MouseClick(object sender, MouseEventArgs e) //chart1是你建的chart控件,实际名字根据你自己代码里的命名 { HitTestResult hit = chart1.HitTest(e.X, e.Y); if (hit.Series != null) { var xValue = hit.Series.Points[hit.PointIndex].XValue; var yValue = hit.Series.Points[hit.PointIndex].YValues.First(); textBox1.Text = string.Format("{0:F0},{1:F0}", "x:"+xValue, "y:"+yValue);//textbox1也是自己建的一个专门用来显示的内容框,也可以用messagebox直接弹出内容 } else { textBox1.Text="未点击到波形曲线"; } }
vv彭
2021/01/18
3.5K0
c# 动态实例化一个泛型类
动态实例化一个类,比较常见,代码如下 namespace ConsoleApp2 { public class MyClass { } } Type classType =
我思故我在
2018/05/11
1.2K0
c# 动态实例化一个泛型类
动态实例化一个类,比较常见,代码如下 namespace ConsoleApp2 { public class MyClass { } } Type classType =
我思故我在
2018/07/05
1.1K0
matlab plotyy 坐标轴设置,[转载]Matlab plotyy画双纵坐标图实例[通俗易懂]
legend([H1,H2],{‘y1 = 200*exp(-0.05*x).*sin(x)’;’y2 =
全栈程序员站长
2022/06/28
1.2K0
C# UDP操作实例
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Sockets; using System.Ne
zls365
2020/08/19
1.2K0
C# UDP操作实例
C# 实例:重写(override)
1、重写(override):子类中为满足自己的需要来重复定义某个方法的不同实现,需要用 override 关键字,被重写的方法必须是虚方法,用的是 virtual 关键字。它的特点是(三个相同):
zls365
2020/11/17
2.4K0
C# 实例:重写(override)
C# TASK使用实例
4、任务停止运行,等待他的任何子任务时,状态变成WaitingForChildrenToComplete。
zls365
2020/08/19
1.3K0
C# TASK使用实例
C#多线程实例
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace 线程实例1 {
zls365
2020/08/19
8170
C#多线程实例
C# API操作实例
/*c#在调用c++方法或者window api时不能象调用c#本身写的dll类库那样直接通过引用dll就可以调用相应的方法, 而是要把要引用的dll放到bin中,现通过[DllImport("User32.dll")]引用*/
zls365
2020/08/19
6350
C# API操作实例
c# list<T>操作实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { List<string[]> str1
zls365
2020/08/19
8660
c# list<T>操作实例
C#–遍历目录实例
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116042.html原文链接:https://javaforall.cn
全栈程序员站长
2022/01/27
8340
C#–遍历目录实例
C#实例:串口通讯
 最近在研究串口通讯,其中有几个比较重要的概念,RS-232这种适配于上位机和PC端进行连接,RS-232只限于PC串口和设备间点对点的通信。它很简单的就可以进行连接,由于串口通讯是异步的,也就是说你可以同时向两端或者更多进行数据发送,它们之间的传输数据类型是byte,串口通信最重要的参数是波特率、数据位、停止位和奇偶校验。对于两个进行通信的端口,这些参数必须匹配。
zls365
2020/08/19
3.6K1
C#实例:串口通讯
C# ref实例讲解
C#有两种参数传递方式:传值和引用,传值就是变量的值,而引用则是传递的变量的地址;
zls365
2020/08/19
5410
C# ref实例讲解
可视化 坐标系统
ggplot2可以通过coord_flip()切换x和y轴。例如,如果你想要水平箱形图。 这对长标签也很有用:很难让它们在x轴上不重叠的情况下适合。
用户1359560
2018/08/27
5170
可视化 坐标系统

相似问题

类实例化C#

30

C#委托实例化

10

c#对象实例化

50

C#动态实例化

40

C#棱镜:视图实例化之前的实例化模型

13
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文