PointToClient not quite working. (Error details within.) - c#

i'm working on a tower defence for a class exam together with a friend of mine. And i figured i would use "PointToClient" To get the positions of the cursor to send with the tower when ever we want to put it down. But its not quite working. I keep getting the error:
'Vp.PlaceTower'does not contain a definition for 'PointToClient' and no extension method 'PointToClient' accepting a first argument of type 'Vp.PlaceTower' could be found (Are you missing a using directive or an assembly reference?).
The code is as follows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
namespace Vp
{
class PlaceTower : GameWorld
{
private List<Tower> towers = new List<Tower>();
private Point cursorPos;
private Point position;
private Point oldCursorPos;
public void PlaceTower()
{
cursorPos = this.PointToClient(Cursor.Position);
}
}
}

PointToClient is a method that belongs to the class System.Windows.Forms.Control. Does GameWord inherit this class? Your exception is very explanatory.
Make GameWorld inherit Control and you will solve this.

Related

Unable to detect error while using PhotonView.isMine method

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.IO;
using UnityEngine.UI;
public class PhotonPlayerSetup : MonoBehaviourPunCallbacks, IInRoomCallbacks
{
private PhotonView PV;
void Awake()
{
PV = GetComponent<PhotonView>();
}
void Start()
{
if(PV.isMine)
{
}
}
}
While using above mentioned code this error appears:
"PhotonView does not contain a definition for isMine and no
accessible extension method isMine accepting a first argument of
type 'PhotonView' could be found (are you missing a using directive or
an assembly reference?)"
Thank you for choosing Photon!
PhotonView.isMine from PUN Classic was renamed to PhotonView.IsMine in PUN 2.
Make sure to check out the Migration Notes.

C# cant find a unity auto generated class

Okay so I'm learning to use the new InputActions and I've created a C# scripts using
https://prnt.sc/oyaj5l
And this is what I got:
// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class PlayerControls : IInputActionCollection
{
private InputActionAsset asset;
public PlayerControls()
{
///
}
}
But when I try to create an PlayerControls object, I get an error saying
The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)
This is the class where I try to reference it:
using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class FirstPersonController : MonoBehaviour
{
private PlayerControls controls; // ERROR HERE
}
}
Wrap the PlayerControls class in a namespace, then add a using statement in your class that points to the namespace where your PlayerControls class lives.
I solved it!
It looks like Unity has a compile order. I referenced this: http://answers.unity.com/answers/1274460/view.html and managed to solve it after seeing that "Standard Assets" has priority over other assets

Why i'm getting Inconsistent accessibility: field type .... is less accessible than field ? And how to fix it?

Error 1 Inconsistent accessibility: field type 'Youtube_Manager.Ffmpeg' is less accessible than field 'Youtube_Manager.ScreenShot.fmpeg'
In a class top i added:
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
namespace Youtube_Manager
{
public class ScreenShot
{
#region Global Variables
public static Ffmpeg fmpeg;
Then i'm calling to use fmpeg in another class in a timer click event:
ScreenShot.fmpeg.Close();
And i'm getting in the class ScreenShot on the fmpeg the error:
Error 1 Inconsistent accessibility: field type 'Youtube_Manager.Ffmpeg' is less accessible than field 'Youtube_Manager.ScreenShot.fmpeg'
And this is the top of the class Ffmpeg:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using DannyGeneral;
namespace Youtube_Manager
{
class Ffmpeg
{
NamedPipeServerStream p;
String pipename = "mytestpipe";
System.Diagnostics.Process process;
string ffmpegFileName = "ffmpeg.exe";
string workingDirectory;
public Ffmpeg()
{
Even if i change the variable fmpeg from static to public i'm getting on it the same error.
Top-level C# classes are internal by default. Internal has a lower visibility than public. Use public class Ffmpeg to make the class public.

Where to store information about point in console application?

I need to create a struct storing four points. I wanted to create a Point variable, but it looks I can't use System.Drawing in console application. What should I use?
you should add a reference to System.Drawing.dll and then add using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
}
}
}

Accessing MainWindow Properties from other classes

I can modify/access controls and MessageBox with ease in the MainWindow.xaml.cs file of my WPF application. However, when I create some folders and add classes there, I no longer have access to MessageBox nor do I have see the control names in the Intellisense dropdown.
(This seems quite elementary but I'm new to C# and WPF)
You must be missing a namespace. You could do something like this:
MainWindow.cs:
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace YourNameSpaceHere
{
public partial class MainWindow : Window
{
internal static string message_ = string.Empty;
MainWindow()
{
InitializeComponent();
SetupMessage();
}
private void SetupMessage()
{
message_ = "Hello World!";
}
}
}
OtherFile.cs :
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls; //are you missing this namespace?
namespace YourNameSpaceHere
{
public class Messaging
{
Messaging()
{
MessageBox.Show(MainWindow.message_);
}
}
}
Note that I am using the same namespace in each file and by using the internal keyword the message can be accessed by anything as long as it is in the same namespace. I hope this helps!
Does your classes have the right using statement in that would allow you access to the class you are attempting to access within the new classes you've created?

Categories

Resources