小编Lyn*_*rum的帖子

Unity3D 播放器移动脚本

我有一个脚本可以让你控制一个玩家并跳跃。但是,我正在努力使播放器不断移动,并且无法通过键盘上的 WASD 键进行控制。每当我尝试只使用controller.Move()重力功能时,它就会消失。现在,使用此代码 Gravity 可以工作,但 WASD 也已启用。我的问题是:我怎样才能让这段代码让我的玩家不断移动,并且仍然使用重力?

using UnityEngine;
using System.Collections;

public class PlayerMotor : MonoBehaviour {

    public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;

    private Vector3 moveDirection = Vector3.back;
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded)
        {
            controller.Move (Vector3.back * Time.deltaTime);
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;

        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    } …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unity5

5
推荐指数
0
解决办法
2万
查看次数

C#计时器没停?

这就是我所拥有的,为什么我的计时器没有停止?我不确定我做错了什么.我是C#的新手,我正试图让它成为我的启动画面隐藏(form1)和我的程序启动(samptool)然而我的程序启动但启动画面停留并且计时器重置而不是停止.每6.5秒,应用程序将在新窗口中打开.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
namespace SplashScreen.cs
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 250;
            timer2.Interval = 6500;
            timer1.Start();
            timer2.Start();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.progressBar1.Increment(5);
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            SampTool w = new SampTool();
            Form1 m = new Form1();
            timer1.Enabled = false;
            timer1.Stop(); …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
724
查看次数

Unity3D C#定时器以毫秒为单位显示

我正在尝试将.text更改为以下格式:

00:00:00

但相反,我得到0:00.00000我需要更改以更正我的代码?

private void Update()
{
    if (!chestButton.IsInteractable ()) 
    {
        if (IsChestReady ()) {
            chestButton.interactable = true;
            chestTimer.SetActive (false);
            chestTimerBg.SetActive (false);
            newGift.SetActive (true);
            return;
        }
        //Set Timer
        ulong diff = ((ulong)DateTime.Now.Ticks - lastChestOpen);
        ulong m = diff / TimeSpan.TicksPerMillisecond;
        float secondsLeft = (float)(msToWait - m) / 1000.0f;

        string r = " ";
        //Hours
        r += ((int)secondsLeft / 3600).ToString() + ": ";
        secondsLeft -= ((int)secondsLeft / 3600) * 3600;
        //Minutes
        r += ((int)secondsLeft / 60).ToString();
        //Seconds
        r += (secondsLeft % …
Run Code Online (Sandbox Code Playgroud)

c# android unity-game-engine

2
推荐指数
1
解决办法
752
查看次数

在C#中选择MySQL数据

我想使用 C# 登录该程序,使用存储在 phpmyadmin 中的 SQL 数据库中的用户名和密码。这是我到目前为止所拥有的。

private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnection connection;
            string server = "localhost";
            string database = "login";
            string uid = "root";
            string password = "";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";


            connection = new MySqlConnection(connectionString);

            try
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                    Form1 frm = new Form1(this);
                    frm.Show();
                    Hide();
                } …
Run Code Online (Sandbox Code Playgroud)

c# mysql visual-studio-2015

1
推荐指数
1
解决办法
8708
查看次数